understanding list scope
Alex
metallourlante at gmail.com
Sun Sep 21 08:51:13 EDT 2008
Hi all!
I have a problem understanding the behaviour of this snippet:
data_set = ({"param":"a"},{"param":"b"},{"param":"c"})
for i in range(len(data_set)):
ds = data_set[:]
data = ds[i]
if i == 1: data['param'] = "y"
if i == 2: data['param'] = "x"
print data_set
This script print out:
({'param': 'a'}, {'param': 'y'}, {'param': 'x'})
Why? I'm coping data_set in ds so why data_set is changed?
Thanks in advance.
Alex
More information about the Python-list
mailing list