indexing lists/arrays question

a oxfordenergyservices at googlemail.com
Thu May 13 11:45:54 EDT 2010


On 13 May, 16:19, Tim Chase <python.l... at tim.thechases.com> wrote:
> On 05/13/2010 09:36 AM, a wrote:
>
> > 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)
>
> indexes = [i for (i, v) in enumerate(a) where v==3]
>
> > then i want to reference these in a
>
> In a _what_?  You can then do things like
>
>    for i in indexes:
>      print a[i]
>
> (but you already know these are "3", so it's not very exciting...)
>
> -tkc

really its to get the indexes in 1 array where something equals
something then reference these in another array.



More information about the Python-list mailing list