finding a value in a tuple

Dan Allen bigredlinux at yahoo.com
Thu Nov 29 15:49:42 EST 2001


Say I have

mylist = ['one','two','three']

which I presume is a "tuple" as I have been scanning the manual.  Now,
is there a way to run the php-like function in_array() on this. 
Consider this, I want to know if one of the values in that tuple is
exactly equal to "four".  The answer of course is no, but how would I
find it.  Here is what I have so far, which works, but it is ugly..

d = {}
for value in mylist
  d[value] = 1
try:
  if d['four']:
    print "your value was found"
except:
  print "your value was not found"

Two question here, is that a bad use of try/except?  Second is, is
there an array_flip, or do you just have to do what I did above?  I
would imagine there is a way to search down the tuple.

Thanks!

Dan



More information about the Python-list mailing list