Hi friends,
I am trying to write a histogram function in Python. This is what I have managed so far:
def histogram(s):
d={}
for c in s:
if c not in d:
d[c]=1
else:
d[c]+=1
return d
h=histogram('brontosaurus')
print h
However, I want to use the get() function in the dictionary module to re-write the above code. I also want to eliminate the 'if' statement. Can this be done?
Thank You.
PS: I am a Python newbie. :)