Sorting part of a list

Sibylle Koczian Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Fri Jun 24 07:42:39 EDT 2005


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 the original list. Right so far?

But assignment to the slice:

 >>> ll[2:] = [2, 4]
 >>> ll
[3, 1, 2, 4]

_does_ change my original ll.

What did I misunderstand?

Thanks,
Sibylle

-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE



More information about the Python-list mailing list