[Tutor] List-question

Øyvind python at kapitalisten.no
Mon Dec 19 13:45:52 CET 2005


I have one function that finds some values. Then I want that function to
find new values based on the values it found first. However, by just
looping, it starts on an eternal job.

As illustrated in:
>>> list = [1,2,3]
>>> list2 = list
>>> list2
[1, 2, 3]
>>> for i in list:
... 	print i
... 	list2.append(4)
...
1
2
3
4
4
4 and it will forever continue with 4's.

Why would list be expanded with the values of list2? How can I copy the
result from one list, and do things with the list without getting it to
expand?


-- 
This email has been scanned for viruses & spam by Decna as - www.decna.no
Denne e-posten er sjekket for virus & spam av Decna as - www.decna.no



More information about the Tutor mailing list