Hello all,
Behold:
--
a = [ 'Foo', 'Bar' ]
b = [ 'Boo', 'Far' ]
q = [ a, b ]
print q[0][0]
print q[1][1]
a[0] = 'Snoo'
b[1] = 'Gnuu'
print q[0][0]
print q[1][1]
--
This will output:
Foo
Far
Snoo
Gnuu
I assume it does so because q stores _references_ to a and b. How
would
Jan Danielsson [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]:
Hello all,
Behold:
--
a = [ 'Foo', 'Bar' ]
b = [ 'Boo', 'Far' ]
q = [ a, b ]
print q[0][0]
print q[1][1]
a[0] = 'Snoo'
b[1] = 'Gnuu'
print q[0][0]
print q[1][1]
--
This will output:
Foo
On 2005-06-02 14:43:40, Jan Danielsson wrote:
a = [ 'Foo', 'Bar' ]
b = [ 'Boo', 'Far' ]
q = [ a, b ]
Or, better yet, how do I store a and b in q, and then tell Python
that I want a and b to point to new lists, without touching the contents
in q?
There are several ways to create a copy
Stian Søiland wrote:
There are several ways to create a copy of a list:
[snip]
a2 = list(a) # create a new list object out of any sequence
I'll just point out that FWIW, this is by far my favorite idiom of the
ones offered because it applies to pretty much all the builtin container