Re: [Tutor] Finding Match in nexted tuple
Magnus Lycka
magnus at thinkware.se
Wed Apr 21 20:57:41 EDT 2004
Tim Johnson wrote:
> Let's say I have a list of zip codes returned from a MySQLdb query
> zip_code_list = (('84536',), ('85003',), ('85004',), ('85006',),
> ('85007',), ('85008',))
> # and I want to look for a match for a value like '85004'
If you know that the format is exactly like that, you can
simply do:
if ('85004',) in zip_code_list:
print "Found!"
..but maybe that's not what you intended? If '85004' might
just be in an arbitrary position in a sequence of tuples with
more columns than the zip codes, you could for instance do:
if '85004' in str(zip_code_list):
print "Found!"
--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus at thinkware.se
More information about the Tutor
mailing list