position in a for loop?

Pierre Quentel quentel.pierre at free.fr
Wed Dec 31 06:04:05 EST 2003


With a combination of enumerate and list comprehensions :

>>> food=['linguine','Spam','clams','Spam','steak']
>>> [ i for i,v in enumerate(food) if v=='Spam' ]
[1, 3]

@+
Pierre






More information about the Python-list mailing list