On 2010-05-13, a <oxfordenergyservi...@googlemail.com> 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) > > then i want to reference these in a > > ie what i would do in IDL is > > b=where(a eq 3) > a1=a(b) > > any ideas?
For a sorted sequence the bisect module is a good start. >>> start = bisect.bisect_left(a, 3) >>> end = bisect.bisect_right(a, 3, bs) >>> b = list(range(start, end)) >>> b [1, 2] If the list isn't necessarily sorted, try filter and enumerate. >>> b = [a for a,b in filter(lambda x: x[1]==3, enumerate(a))] >>> b [1, 2] -- Neil Cerutti *** Your child was bitten by a Bat-Lizard. *** -- http://mail.python.org/mailman/listinfo/python-list