tuple pairs, finding minimum, python -



tuple pairs, finding minimum, python -

i have info comes tuple pairs within python, e.g.

data = [ (1, 7.57), (2, 2.1), (3, 1.2), (4, 2.1), (5, 0.01), (6, 0.5), (7, 0.2), (8, 0.6)]

how may find min of dataset comparing of sec number only? i.e. data[0][1] = 7.57, data[1][1] = 2.1.. min( info ) = (5, 0.01)

i see min( info ) returns (1, 7.57), take right minimum within pair, though not of dataset.

in [2]: min(data, key = lambda t: t[1]) out[2]: (5, 0.01)

or:

in [3]: import operator in [4]: min(data, key=operator.itemgetter(1)) out[4]: (5, 0.01)

python tuples min

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -