This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: List of sets initialization behavior problems
Type: enhancement Stage: resolved
Components: None Versions: Python 3.1, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: adamnemecek, eric.smith
Priority: normal Keywords:

Created on 2010-09-23 20:39 by adamnemecek, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg117231 - (view) Author: Adam Nemecek (adamnemecek) Date: 2010-09-23 20:39
I'm not sure if this is the intended behavior, but it seems unusual to me.
a = [set([]) for i in range(2)] evaluates to a list [set([]),set([])] and
b= 2*[set([])] evaluates to [set([]),set([])].
Nothing wrong here. 
Nevertheless, if I do a[0].add(1), a has the value [set([1]), set([])] but  b[0].add(1) evaluates to [set([1]), set([1])]. 
I understand that in list b, all of the sets refer to the same object in memory, nevertheless, I do not feel like this is the correct behavior.
msg117235 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-09-23 21:12
This is well defined in Python and will not change.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54141
2010-09-23 21:12:57eric.smithsetstatus: open -> closed

type: enhancement

nosy: + eric.smith
messages: + msg117235
resolution: rejected
stage: resolved
2010-09-23 20:39:06adamnemecekcreate