[Python-Dev] defaultdict and on_missing() (original) (raw)
Edward C. Jones edcjones at comcast.net
Wed Feb 22 21:27:56 CET 2006
- Previous message: [Python-Dev] defaultdict and on_missing()
- Next message: [Python-Dev] defaultdict and on_missing()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Guido van Rossen wrote:
I think the pattern hasn't been commonly known; people have been struggling with setdefault() all these years.
I use setdefault only to speed up the following code pattern:
if akey not in somedict: somedict[akey] = list() somedict[akey].append(avalue)
These lines of simple Python are much easier to read and write than
somedict.setdefault(akey, list()).append(avalue)
- Previous message: [Python-Dev] defaultdict and on_missing()
- Next message: [Python-Dev] defaultdict and on_missing()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]