On Mar 18, 10:48 pm, bearophileH...@ lycos.com wrote:
vorticitywo:
>
Is there a function in Python analogous to the "where" function in
IDL?
>
Python gives very elastic syntax, you can simply do:
>
data = [0,1,2,3,4,2,8,9]
print [pos for pos, el in enumerate(data) if el==2]
>
Bye,
bearophile
Thank you both, a little more cumbersome than I expected, but it does
the job! Thanks!
On Mar 18, 10:48 pm, bearophileH...@ lycos.com wrote:
>
>vorticitywo:
>>
>>
>>Is there a function in Python analogous to the "where" function in
>>IDL?
>>>
>Python gives very elastic syntax, you can simply do:
>>
>data = [0,1,2,3,4,2,8,9]
>print [pos for pos, el in enumerate(data) if el==2]
>>
>Bye,
>bearophile
>>
>
Thank you both, a little more cumbersome than I expected, but it does
the job! Thanks!
>
>
On Mar 18, 10:48 pm, bearophileH...@ lycos.com wrote:
>[...fine solutions to the problem as asked...]
Thank you both, a little more cumbersome than I expected, but it does
the job! Thanks!
The obvious simple near-equivalent is:
data = range(33,99)
print data.index(45)
And "generalize d":
data = [x % 9 for x in range(30)]
result = []
former = -1
try:
while True:
former = data.index(3, former + 1)
result.append(f ormer)
except ValueError:
print result
else:
print 'Nothing found'
Comment