Finding values on sequences and .index()
rhamorim at my-deja.com
rhamorim at my-deja.com
Wed Dec 6 13:15:26 EST 2000
Hi.
I have a list that may have many ocurrences of the same data. How do I
find the indexes for all ocurrences of it? list.index(value) only works
for the first ocurrence.
I thought of this ugly hack below, but I guess there's an easier way.
a = [1, 2, 3, 4, 1, 5, 6, 7, 1, 8, 9, 1]
b = map(None, a, range(len(a)))
N = 1 #value to be searched
c = filter(lambda x, n=N: x[0]==N, b)
d = map(lambda x: x[1], c) #this is the returned index list
Thanks in advance...
Roberto Amorim
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list