Check for dict key existence, and modify it in one step.

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Aug 28 19:22:02 EDT 2007


Ben Finney <bignose+hates-spam at benfinney.id.au> writes:

>     foo.setdefault(whatever, {})
>     foo[whatever].setdefault(someother, 0)
>     foo[whatever] += delta

Should, of course, be:

    foo.setdefault(whatever, {})
    foo[whatever].setdefault(someother, 0)
    foo[whatever][someother] += delta

-- 
 \        "My house is made out of balsa wood, so when I want to scare |
  `\     the neighborhood kids I lift it over my head and tell them to |
_o__)  get out of my yard or I'll throw it at them."  -- Steven Wright |
Ben Finney



More information about the Python-list mailing list