I'm trying to make histogram by python. I am starting with the following snippet:
def histogram(L):
d = {}
for x in L:
if x in d:
d[x] += 1
else:
d[x] = 1
return d
I understand it's using dictionary function to solve the problem.
But I'm just confused about the 4th line: if x in d:
d is to be constructed, there's nothing in d yet, so how come if x in d?