Hi, I didn't notice the 'strange' behavior of list() function until this task.
x=({1,2},{2,3},{3,4}) # tuple of sets
y=list(x) # list based on x
y[1].remove(2)
print x # (set([1, 2]), set([3]), set([3, 4]))
print y # [set([1, 2]), set([3]), set([3, 4])]
Please notice that tuple x is also changed, which is not intended. It seems that x, y are sharing same pieces of memory. I intend to create a new list based on the elements of x, but aim to keep x unchanged while manipulating y.
I tried to google it with keys words like list() + python + init. But I didn't find anything useful and specific on this problem. Guess it is because I didn't get the key words right, and I really don't know...
Please share some insights. A link to a piece of some tutorial will be wonderful. Thanks in advance!
Created at: 2016/06/29 10:45; Updated at: 2016/06/29 22:51