I’m working on a project in which I have a list that contains tuples of a dict and an int. I’m trying to search through each dictionary for a give name but I’m having some trouble.
dicts = [ (somedict, 0), (someOtherDict, 5)]
Before I just had a list of dicts so I could easily search through with
def search(name):
for d in reversed(dicts):
if name in d: return d[name]
But now that I have a list of tuples I’m not quite sure how to search through the dictionaries. Any help or advice would be greatly appreciated. I’m so confused now.
Just use a generator expression to get your dicts:
Alternatively you can use tuple assignment:
but that assumes that all your tuples have 2 values.