[Python-checkins] bpo-36715: Add usage note for dict.fromkeys() (GH-12974)
Raymond Hettinger
webhook-mailer at python.org
Sun Apr 28 03:22:50 EDT 2019
https://github.com/python/cpython/commit/da63b321f63b697f75e7ab2f88f55d907f56c187
commit: da63b321f63b697f75e7ab2f88f55d907f56c187
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019年04月28日T00:22:36-07:00
summary:
bpo-36715: Add usage note for dict.fromkeys() (GH-12974)
files:
M Doc/library/stdtypes.rst
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index aeecdbb24a57..0a6bb149075f 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -4254,7 +4254,10 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
Create a new dictionary with keys from *iterable* and values set to *value*.
:meth:`fromkeys` is a class method that returns a new dictionary. *value*
- defaults to ``None``.
+ defaults to ``None``. All of the values refer to just a single instance,
+ so it generally doesn't make sense for *value* to be a mutable object
+ such as an empty list. To get distinct values, use a :ref:`dict
+ comprehension <dict>` instead.
.. method:: get(key[, default])
More information about the Python-checkins
mailing list