in place-ness of list.append



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
.



Relevant Pages

  • Re: strange behaviour
    ... } until the command to be proven is called for itself. ... I use the SWI-Prolog, which is shipped with SuSE Linux 10.0. ... Append has no clauses -- it's normally a builtin. ...
    (comp.lang.prolog)
  • Re: Fastest way to convert 1000s of YYYYMMDD char dates to real dates?
    ... that dates are stored in tables in YYYYMMDD format, ... strictdate 0 builtin. ... Your append from text takes advantage of that. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: in place-ness of list.append
    ... Bart Van Loon wrote: ... I would like to find out of a good way to append an element to a list ... without chaing that list in place, ... def addnumber(alist, num): ...
    (comp.lang.python)