Pass a list to diffrerent variables.

Dominique Orban do at linux.darktower.net
Sun May 2 10:07:15 EDT 2004


On 2004-05-02, user at domain.invalid <user at domain.invalid> wrote:
> When trying to pass the contents from one list to another this happens:
>
> list = [1,2,3]
> list1 = list
> print list1
>   [1,2,3]
> list.append(7)
> print list1
>   [1,2,3,7]
>
> Whats the easiest way to pass the data in a list, not the pointer, to 
> another variable

Try list1 = list[:] instead. This creates a copy.

D.



More information about the Python-list mailing list