a = [0,1,2,3,4,2,8,9] # method 1 print [i for i in xrange(len(a)) if a[i]==2] def where(a,val): return [i for i in xrange(len(a)) if a[i]==val] # method 2 print where(a,2)



[EMAIL PROTECTED] wrote:
On Mar 18, 10:48 pm, [EMAIL PROTECTED] 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!


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to