Re: Sorting part of a list

2005-06-27 Thread Sibylle Koczian
Dennis Lee Bieber schrieb: > On Fri, 24 Jun 2005 13:42:39 +0200, Sibylle Koczian > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > > > ll[2:] = ... > > is not an object creation, merely an access into an existing object. > That's what I hadn't understood. Although it'

Re: Sorting part of a list

2005-06-24 Thread Benji York
Fuzzyman wrote: > a = ll[2:] > a.sort() > ll[2:] = a > > To do a partial sort, in place, you'll have to subclass list Or be using 2.4: >>> ll = [3, 1, 4, 2] >>> ll[2:] = sorted(ll[2:]) >>> ll [3, 1, 2, 4] -- Benji York -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting part of a list

2005-06-24 Thread John Machin
Sibylle Koczian wrote: > Hello, > > I thought I understood list slices, but I don't. I want to sort only the > last part of a list, preferably in place. If I do > > >>> ll = [3, 1, 4, 2] > >>> ll[2:].sort() It may help in unravelling any bogglement to point out that this is equivalent to te

Re: Sorting part of a list

2005-06-24 Thread Fuzzyman
You can assign to a slice in place, but referencing a slice creates a copy. I think you understand it quite well :-) a = ll[2:] a.sort() ll[2:] = a To do a partial sort, in place, you'll have to subclass list - but you'll still end up doing something similar unless you delve into C or write your

Sorting part of a list

2005-06-24 Thread Sibylle Koczian
Hello, I thought I understood list slices, but I don't. I want to sort only the last part of a list, preferably in place. If I do >>> ll = [3, 1, 4, 2] >>> ll[2:].sort() >>> ll [3, 1, 4, 2] ll isn't changed, because ll[2:] is a copy of the last part of the list, and this copy is sorted, not