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'
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
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
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
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