Simple question on indexing

Christoph Haas email at christoph-haas.de
Fri Dec 1 11:36:39 EST 2006


On Friday 01 December 2006 17:21, Tartifola wrote:
> I would like to obtain the position index in a tuple when an IF
> statement is true. Something like
>
> >>>a=['aaa','bbb','ccc']
> >>>[ ??? for name in a if name == 'bbb']
> >>>1

What about:

  [ x for x,y in enumerate(a) if y == 'bbb' ]

Or if there is only one element 'bbb':

  a.index('bbb')

Kindly
 Christoph



More information about the Python-list mailing list