Iterating over tuple entries in a list
George Yoshida
ml at dynkin.com
Thu Mar 11 08:22:41 EST 2004
Peter Otten wrote:
> If you are really lazy:
>
>
>>>>myList = [(1.1, "file1"), (1.2, "file2"), (1.9, "file3")]
>>>>zip(*myList)[0]
>
> (1.1000000000000001, 1.2, 1.8999999999999999)
Or you could do it:
>>> myList = [(1.1, "file1"), (1.2, "file2"), (1.9, "file3")]
>>> map(lambda x:x[0], myList)
[1.1000000000000001, 1.2, 1.8999999999999999]
--
George
More information about the Python-list
mailing list