in place-ness of list.append
BJörn Lindqvist
bjourne at gmail.com
Mon Feb 5 08:44:24 EST 2007
More information about the Python-list mailing list
Mon Feb 5 08:44:24 EST 2007
- Previous message (by thread): Why less emphasis on private data?
- Next message (by thread): in place-ness of list.append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/5/07, skip at pobox.com <skip at pobox.com> wrote: > > Bart> #-------------------------------------------------- > Bart> def addnumber(alist, num): > Bart> """ work around the inplace-ness of .append """ > Bart> mylist = alist[:] > Bart> mylist.append(num) > Bart> return mylist > Bart> #-------------------------------------------------- > > Such an operation will be O(N**2), and thus expensive if performed > frequently on lists of moderate length. I've never been tempted to do this. How can that be? Making a copy of a list is O(N), isn't it? -- mvh Björn
- Previous message (by thread): Why less emphasis on private data?
- Next message (by thread): in place-ness of list.append
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list