in place-ness of list.append
Bart Van Loon
bbbart at inGen.be
Mon Feb 5 05:44:33 EST 2007
Hi all,
I would like to find out of a good way to append an element to a list
without chaing that list in place, like the builtin list.append() does.
currently, I am using the following (for a list of integers, but it
could be anything, really)
#--------------------------------------------------
def addnumber(alist, num):
""" work around the inplace-ness of .append """
mylist = alist[:]
mylist.append(num)
return mylist
#--------------------------------------------------
and I am wondering if this is good practice or not.
any advice on this matter?
thanks!
--
regards,
BBBart
"Someday I'll write my own philosophy book." -Calvin
More information about the Python-list
mailing list