Getting at an item in a list of tupples
Emile van Sebille
emile at fenx.com
Tue Dec 11 19:31:12 EST 2001
"Bob Greschke" <bob at passcal.nmt.edu> wrote in message
news:9v66mi$17mi$1 at newshost.nmt.edu...
> Here's what I've got
>
> a = []
> a.append((ints, floats, strings))
> a.append((ints, floats, strings))
> a.append((ints, floats, strings))
> a.append((ints, floats, strings))
> ...
>
> I want to do something like
>
> print max(of all of the floats)
> print min(of all of the floats)
>
> In general, how do you get at the floats (or ints, or strings)? We
> can see doing something with map() calling a function that returns the
> second item, but isn't there something a little simpler?
>
Assuming you've got tuples of length 3 where index 1 is always a float:
>>> a = []
>>> a.append((1,2.,'3'))
>>> a.append((11,12.,'13'))
>>> a.append((21,22.,'23'))
>>> a
[(1, 2.0, '3'), (11, 12.0, '13'), (21, 22.0, '23')]
>>> max([i[1] for i in a])
HTH,
--
Emile van Sebille
emile at fenx.com
---------
More information about the Python-list
mailing list