bpo-36715: Add usage note for dict.fromkeys() (GH-12974) · python/cpython@da63b32

Original file line numberDiff line numberDiff line change

@@ -4254,7 +4254,10 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:

42544254

Create a new dictionary with keys from *iterable* and values set to *value*.

42554255
42564256

:meth:`fromkeys` is a class method that returns a new dictionary. *value*

4257-

defaults to ``None``.

4257+

defaults to ``None``. All of the values refer to just a single instance,

4258+

so it generally doesn't make sense for *value* to be a mutable object

4259+

such as an empty list. To get distinct values, use a :ref:`dict

4260+

comprehension <dict>` instead.

42584261
42594262

.. method:: get(key[, default])

42604263