Why does changing 1 list affect the other?

From: oom (oom_at_xxnospamxx.ps.gen.nz)
Date: 11/06/03


Date: Thu, 06 Nov 2003 16:36:08 +1300

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!



Relevant Pages

  • How best to teach newbie at algorithms (was: coerce for arbitrary types)
    ... the algorithm itself is essentially last-in first-out, ... newbie needs to learn is how to write useful tools that go beyond ... lists, as vectors, and as structs, to show how the same API can be ... If you want to sort a list, you have to use the result of SORT. ...
    (comp.lang.lisp)
  • re: Time to shut down this list?
    ... I'm a newbie, and until now, a lurker. ... I see little that truly DOES follow the charter. ... lists with pretty sad results. ... You suggested disbanding the list. ...
    (freebsd-newbies)
  • Re: Q: List Policy
    ... This may cause the newbie to go back to Vista. ... One of the *BSD mailing lists explicitly CC's because there are newbies ... so any polite message is likely to be taken as a "why pick on ... posters with an @debian.org address, ...
    (Debian-User)
  • RE: FreeBSD-newbies shutting down? (was: no freebsd-beginners list?)
    ... Yes, that was my intention. ... I will stay here if this list is for the newbie and the advanced user as ... Subject: FreeBSD-newbies shutting down? ... There are a number of problems with having two lists: ...
    (freebsd-questions)
  • re: Time to shut down this list?
    ... I'm a newbie, and until now, a lurker. ... I see little that truly DOES follow the charter. ... lists with pretty sad results. ...
    (freebsd-newbies)