sql - Select tuple member from a list with condition in python/pyodbc -


i have list this

a =[ ( 1, 10, 3), (1, 2, 3), (1, 11, 3), (2, 6, 4), (2, 5, 4) ] 

i need make list like

b = [ ( 1, 2, 3), (2, 5, 4) ]  

the condition if first , third values of member of equal member select member having smallest 2nd value.

in example member of 5 , of 2 group having first , third members equal. in case numbers might high. not figure out how python 2.7.

its helpful if query ok pyodbc considering each member of record , member of each tuple column.

an alternate:

from sys import maxint  =[ ( 1, 10, 3), (1, 2, 3), (1, 11, 3), (2, 6, 4), (2, 5, 4) ] results = {} x, y, z in a:     key = (x, z)     results[key] = min(y, results.get(key, maxint))  results = [(x, y, z) (x, z), y in results.items()]  print results 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -