[issue32194] When creating list of dictionaries and updating datetime objects one by one, all values are set to last one of the list.

Gareth Rees report at bugs.python.org
Fri Dec 1 07:04:37 EST 2017


Gareth Rees <gdr at garethrees.org> added the comment:

The behaviour of the * operator (and the associated gotcha) is documented under "Common sequence operations" [1]:

    Note that items in the sequence s are not copied; they are referenced
    multiple times. This often haunts new Python programmers ...

There is also an entry in the FAQ [2]:

    replicating a list with * doesn’t create copies, it only creates
    references to the existing objects

[1] https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range
[2] https://docs.python.org/3/faq/programming.html#faq-multidimensional-list

----------
nosy: +gdr at garethrees.org
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32194>
_______________________________________


More information about the Python-bugs-list mailing list