[issue10533] defaultdict constructor with a concrete value

Łukasz Langa report at bugs.python.org
Thu Nov 25 18:36:52 CET 2010

Łukasz Langa <lukasz at langa.pl> added the comment:

Both arguments are true and definitive. Last possibility would be to introduce a factory function for defaultdicts that would only accept concrete values:

  from collections import fallbackdict

Then this factory could produce defaultdict instances like this:

  fallbackdict(0, some_key=1) --> defaultdict(lambda: 0, some_key=1)

That would be safe for future type changes as well.

If this version does not sound appealing, I can't see any other way of reliably introducing this shortcut.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list