I would like to add new keys to an empty dictionary as it goes/reads through my list. I got this to work when I used a list containing only numbers. However, if I try this with a list which contains strings and numbers I get a KeyError for the first string in the list. Could anyone maybe tell me why this is, or how I can fix it?
di = {}
stuff = ['sun', 20, 20, 14.3, 'sun', 'Flower']
for thing in stuff:
if thing not in stuff:
di[thing] = 1
else:
di[thing] += 1
print(di)