Newbie question: Allocation vs references
jan.danielsson at gmail.com
Thu Jun 2 14:43:40 CEST 2005
a = [ 'Foo', 'Bar' ]
b = [ 'Boo', 'Far' ]
q = [ a, b ]
a = 'Snoo'
b = 'Gnuu'
This will output:
I assume it does so because q stores _references_ to a and b. How
would do I do if I want to copy the list? I.e. I want the output from
the code above to be:
..even if a = 'Snoo' and b = 'Gnuu' remain where they are.
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
C equivalent of what I want to do:
a = calloc(n, size);
q = a;
a = calloc(n, size); // new list; 'q' is unaffected if I change 'a'
More information about the Python-list