Syntax: pointers versus value

Tino Lange tl_news at nexgo.de
Wed Jul 30 14:00:24 EDT 2003


On Wed, 30 Jul 2003 13:46:29 -0400, Danny Castonguay
<castong at mathstat.concordia.ca> wrote:

>new_graph = initial_graph[:]
>	initial_graph is [[2, 3], [1], [1]]
>	initial_graph is [[2, 3], [1], [1]]
>	initial_graph is [[2, 3], [1, 3], [1]]
>	initial_graph is [[2, 3], [1, 3], [1, 2]]

Hi!

Now you have lists in lists. This is another situation.
 
new_graph = initial_graph[:] will really make a copy of the outer list
- but this outer list contains no values but once again pointers to
other objects. 

Use the copy-module for nested copy things like that:
http://www.python.org/doc/current/lib/module-copy.html

Cheers,

Tino





More information about the Python-list mailing list