where function

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Mar 18 18:48:55 EDT 2007


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




More information about the Python-list mailing list