[docs] A bug in python 2.7.12 and 3.5.2 ?
Xiang Gao
Xiang.Gao at esi-group.com
Mon Apr 10 16:08:19 EDT 2017
Hi,
I noticed something strange when initializing an empty list of a given size using:
>>> a = [ [] ] * 3 # create an empty list of size 3, with each element being an empty list
>>> a[1].append('a') # modify element[1], leave element[0] and [2] unchanged.
>>> a
>>> [ ['a'], ['a'], ['a'] ] # Result suggests all elements have shared references, that doesn't look right.
This is not critical, since I can re-initialize the empty list: (But, it would be nice to fix it. )
>>> for i in range(len(a)):
>>> a[i] = []
>>>
>>> a[1].append('a')
>>> a
>>> [ [], ['a'], [] ] # This is what I expected.
Thanks for your attention !
Xiang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20170410/bde258e0/attachment.html>
More information about the docs
mailing list