finding a value in a tuple
Carel Fellinger
cfelling at iae.nl
Thu Nov 29 16:58:17 EST 2001
Dan Allen <bigredlinux at yahoo.com> wrote:
> Say I have
> mylist = ['one','two','three']
> which I presume is a "tuple" as I have been scanning the manual. Now,
it's a list. A tuple would use () instead of []. Both are sequnces.
> is there a way to run the php-like function in_array() on this.
I don't know php, but from the example code I guess you're looking for:
if "four" in mylist:
print "your value was found"
else:
print "your value was not fond"
> 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
I personally would go for the simpler:
if d.has_key("four"):
....
> there an array_flip, or do you just have to do what I did above? I
and what is array_flip supposed to be doing?
--
groetjes, carel
More information about the Python-list
mailing list