[issue30040] new empty dict can be more small

Josh Rosenberg report at bugs.python.org
Mon Apr 17 21:44:38 EDT 2017


Josh Rosenberg added the comment:

For the record, legitimate case when many empty dicts are created, and few are populated, is the collections-free approach to defaultdict(dict):

    mydict.setdefault(key1, {})[key2] = val

For, say, 100 unique key1s, and 10,000 total key1/key2 pairs, you'd create 10,000 empty dicts, discarding 9,900 of them. Granted, collections.defaultdict(dict) is even better (avoids the 9,900 unused dicts entirely), but I see the setdefault pattern enough, usually with list or dict, that it's not totally unreasonable to account for it.

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30040>
_______________________________________


More information about the Python-bugs-list mailing list