in place-ness of list.append
Robin Becker
robin at reportlab.com
Mon Feb 5 06:07:02 EST 2007
Bart Van Loon wrote:
> Hi all,
>
.......
>
> #--------------------------------------------------
> 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?
.......
would it not be simpler to just use
..... alist+[num].....
where you need it? Seems more natural than
def addnumber(alist,num):
return alist+[num]
and then
......addnumber(alist,num)......
--
Robin Becker
More information about the Python-list
mailing list