Search in python tuple list -
db = [('cat',15,22),('dog',28,30),('human',27,80)]
now want create search 'dog' returned value db[1]
. can't still figure out (i know use sth for item in db: if 'dog' in item[:]
don't know how put really.
please help?
items = [i in db if 'dog' in i] items[0] if items else none # ('dog', 28, 30)
Comments
Post a Comment