[issue23971] dict(list) and dict.fromkeys() doesn't account for 2/3 fill ratio

Josh Rosenberg report at bugs.python.org
Fri Apr 17 02:06:55 CEST 2015


Josh Rosenberg added the comment:

You shouldn't presize when the input is a potentially non-unique iterable. It makes sense to presize for inputs of type dict or set, but for a list, the assumption is that many duplicates will be present, since deduping is a common use case for dicts (less so with the advent of sets, but still common enough to support without massive overallocation of memory).

In short, dict([(1, 2)] * 1000000) should not involve allocating GB of memory for the dict up front.

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

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


More information about the Python-bugs-list mailing list