def extract(lst,item):
for i in lst:
if i.get(item):
return i[item]
print(extract([{'coin':0},{'xp':5}], 'coin'))
This code must return the value 0 as far as I understand but instead returns None. When I change the value of 0 to anything else it works correctly; looks like the only problem is that the function returns None instead of 0. The purpose of this function is to iterate through a list of dictionaries (lst) and return the value associated with the key (item).