[Tutor] Ingenious script (IMO)

Kent Johnson kent37 at tds.net
Mon Aug 6 16:44:38 CEST 2007

Dick Moores wrote:
> Gotta say though, I still don't understand how the defaultdict works here.

Did you try the docs?

If coinCount were an ordinary dict, the line
   coinCount[deno] += 1

would have to be written as
   coinCount[deno] = coinCount.get(deno, 0) + 1

Using defaultdict(int) makes the use of 0 as the default value 
automatic. (Actually the default value is obtained by calling int(), 
whose value is 0.)


More information about the Tutor mailing list