partial list sort

Terry Reedy tjreedy at
Wed Oct 9 20:30:17 CEST 2002

"jsaul" <jsaul at> wrote in message
news:20021009163345.GD1157 at
> * Eddie Corns [2002-10-09 14:48]:
> > Hint: list[x:y] is a COPY of the elements ie a new list.
> That's what I also thought initially.

Then you were correct and should have programmed with that in mind.  I
gave you the fix you need.  In Python, a slice of a builtin sequence
type is a separate sequence of the same type.  Period.  No argument

User-defined classes can do otherwise.  In Numerical Python, a slice
of an array is not an array but a view into the same array.  This is
for efficiency when working with mega-item arrays, but it is not
standard Python.

>But if in 'sort_components' I introduce the assignment
>     list[0][0] = 9

Irrelevant.  The copy is a shallow (1 level) copy.  Here you are
reaching into and modifying a 2-list that is a member of both the
original list and the slice extracted from it.

Terry J. Reedy

More information about the Python-list mailing list