in place-ness of list.append
- From: Bart Van Loon <bbbart@xxxxxxxx>
- Date: Mon, 5 Feb 2007 15:44:33 +0500
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
.
- Follow-Ups:
- Re: in place-ness of list.append
- From: Robin Becker
- Re: in place-ness of list.append
- From: skip
- Re: in place-ness of list.append
- From: Kent Johnson
- Re: in place-ness of list.append
- Prev by Date: Re: Will Python Run On Microsoft Vista?
- Next by Date: Inheriting str object
- Previous by thread: python references
- Next by thread: Re: in place-ness of list.append
- Index(es):
Relevant Pages
|