Why does changing 1 list affect the other?

oom oom at xxnospamxx.ps.gen.nz
Thu Nov 6 04:36:08 CET 2003


I am a bit of a newbie when it comes to python, when working with
lists today I noticed some very odd behaviour, any suggestions
welcome:

Python 2.2.3 (#1, Nov  6 2003, 14:12:38) 
[GCC 3.3.2 20031022 (Gentoo Linux 3.3.2-r2, propolice)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> firstlist=['item1','item2','item2']
>>> secondlist=firstlist
>>> print (firstlist,secondlist)
(['item1', 'item2', 'item2'], ['item1', 'item2', 'item2'])
>>> firstlist[0]='strangeness'
>>> print (firstlist,secondlist)
(['strangeness', 'item2', 'item2'], ['strangeness', 'item2', 'item2'])
>>> 

why does altering one list affect the other list ? it is driving me
insane!





More information about the Python-list mailing list