Inconsistent list/pointer problem
Eduardo "EdCrypt" O. Padoan
eopadoan at altavix.com
Fri Feb 2 06:03:15 EST 2007
> def myFunc(listA):
> listB = listA
> work on & modify listB
> return(listB)
def my_func(listA):
listB = listA[:]
#work on & modify listB
return listB
Attribution makes the name t the left 'point' to the result of the
expression at the right.
In your myFunc the expersion at the right is the name listA, at it
willl eval to the list that this references. So you will end with to
references.
In my my_func, the expression at the right is a slicing of the list,
from begin to end (listA[:]). Slicing returns a new list, in this
example, with the same items of the original list. So you end with two
lists, as you wanted.
--
EduardoOPadoan (eopadoan->altavix::com)
Bookmarks: http://del.icio.us/edcrypt
Blog: http://edcrypt.blogspot.com
Jabber: edcrypt at jabber dot org
ICQ: 161480283
GTalk: eduardo dot padoan at gmail dot com
MSN: eopadoan at altavix dot com
--
EduardoOPadoan (eopadoan->altavix::com)
Bookmarks: http://del.icio.us/edcrypt
Blog: http://edcrypt.blogspot.com
Jabber: edcrypt at jabber dot org
ICQ: 161480283
GTalk: eduardo dot padoan at gmail dot com
MSN: eopadoan at altavix dot com
More information about the Python-list
mailing list