Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Doc/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,15 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
as if they were passed to the :class:`dict` constructor, including keyword
arguments.

Note that this means ``defaultdict(default_factory=list)`` (for example),
will create a dict with a key of ``'default_factory'`` and a value of
:class:`list`. Instead, call ``defaultdict(list)``.

>>> defaultdict(default_factory=list)
defaultdict(None, {'default_factory': <class 'list'>})
>>> defaultdict(list)
defaultdict(<class 'list'>, {})
>>>

:class:`defaultdict` objects support the following method in addition to the
standard :class:`dict` operations:
Expand Down
4 changes: 4 additions & 0 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2476,6 +2476,10 @@ a new value when a key is not present, in __getitem__ only.\n\
A defaultdict compares equal to a dict with the same items.\n\
All remaining arguments are treated the same as if they were\n\
passed to the dict constructor, including keyword arguments.\n\
\n\
Note that this means defaultdict(default_factory=list) (for\n\
example), will create a dict with a key of 'default_factory'\n\
and a value of <class 'list'>. Instead, call defaultdict(list).\n\
");

/* See comment in xxsubtype.c */
Expand Down
Loading