get method
Scott David Daniels
Scott.Daniels at Acm.Org
Mon Dec 29 20:07:32 EST 2008
Ross wrote:
> ... Use get to write histogram more concisely. You should be able to
> eliminate the if statement.
>
> def histogram(s):
> d = dict()
> for c in s:
> d[c]= d.get(c,0)
> return d
>
> This code returns a dictionary of all the letters to any string s I
> give it but each corresponding value is incorrectly the default of 0.
> What am I doing wrong?
How is this code supposed to count?
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list