[Tutor] Copying list contents

Kalle Svensson kalle@lysator.liu.se
Mon, 29 Jul 2002 07:09:11 +0200


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[Guillermo Fernandez]
> Is there a way of copying lists cleanly, or will I have to create a
> recursive list copy function?

There is the deepcopy function in the copy module.
http://python.org/doc/current/lib/module-copy.html

Also note that to perform a shallow copy on a list, a common idiom is
to use slice notation:

>>> list2 = list1[:] # creates a shallow copy of list1

Peace,
  Kalle
- -- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>

iD8DBQE9RM3ydNeA1787sd0RAoOEAJ9D1XUBe9MLzqrLFXMZU83XBqTCEwCfTB1o
4+cV2s0SsRg3ycWe+4WopdY=
=T9Vq
-----END PGP SIGNATURE-----