Iterating over tuple entries in a list

Dirk Zimmermann python-list at d1z1.de
Wed Mar 10 16:09:22 EST 2004


Hi,

I have the following problem:

I have a list with tuples in it, looking like this:

myList = [(1.1, "file1"), (1.2,"file2), (1.9, "file3")]

(I want to store a number calculated from a file together with the
file.) Than I want to use functions expecting a list of floats. Is there
an easy way to slice myList? I know, that:

myList[2][0]

gives:
1.9

But:

myList[0:2][0]

does _not_ give something like:

[1.1, 1.2, 1.9]

By now I loop over the list, select the numbers and store them in a new
list. But I don't like that way very much. Is there a "better" way?


Best,
Dirk





More information about the Python-list mailing list