indexing lists/arrays question

Neil Cerutti neilc at norwich.edu
Thu May 13 11:08:44 EDT 2010


On 2010-05-13, Stefan Behnel <stefan_ml at behnel.de> wrote:
> a, 13.05.2010 16:36:
>> this must be easy but its taken me a couple of hours already
>>
>> i have
>>
>> a=[2,3,3,4,5,6]
>>
>> i want to know the indices where a==3 (ie 1 and 2)
>
>    indices = [ i for i,item in enumerate(a) if item == 3 ]

That form of list comprehension is preferable to my use of filter
posted elsewhere, but it didn't occur to me. Oops!

-- 
Neil Cerutti
*** Your child was bitten by a Bat-Lizard. ***



More information about the Python-list mailing list