Hello all. I've recently been looking at some pygame examples by Mekire, and have realized that I have basically no knowledge of dictionaries. So I'm working through a tutorail. In the tutorial the following function has been defined:

- Code: Select all
`def histogram(s):`

d = dict()

for letter in s:

if letter not in d:

d[letter] = 1

else:

d[letter] += 1

return d

h = histogram('brontosaurus')

print(h)

Simple enough, right? Then it introduced the .get() method, for example

- Code: Select all
`h.get('a',0)`

>>>1

Now it's asked me to use .get() inside the histogram function, and in doing this I should be ablle to eliminate the if statemetn. Initially, I figured this would be easy:

- Code: Select all
`def hgram(s):`

d = dict()

for letter in s:

d[letter] = d.get(letter,1)

return d

h = hgram('brontosaurus')

print(h)

Of course, this does not work. Now I am stumped. I can't work it out! The worst part is, I bet it's really obvious, and I'm making myself look a fool for not working it out lol! Can anyone give me a hint on this most trivial of problems?