This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list sort is not "in place"
Type: Stage:
Components: Documentation Versions: Python 2.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, shd, tim.peters
Priority: normal Keywords: patch

Created on 2004-12-06 17:15 by shd, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-2.4-not-in-place.diff shd, 2004-12-06 17:15 documentation fix for list sort description
Messages (4)
msg47368 - (view) Author: Heikki Orsila (shd) Date: 2004-12-06 17:15
list sort method says the sort algorithm is "in place",
but it is not. It requires O(N) extra memory at worst
case. A patch is attached that corrects the
documentation in Objects/listobjects.c.


msg47369 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-12-06 17:48
Logged In: YES 
user_id=31435

Sorry, I'm rejecting this.  Of course it's "in place":  x.sort() 
does not return a new list.  Its only visible effect is to 
permute the elements of x.  That's what "in place" means.

That the current implementation may require temp memory is 
irrelevant to that, and *because* it's an internal 
implementation detail, doesn't belong in the docstring.  
The "in place" was added to the docstring because many 
newcomers believed x.sort() left x alone, and returned a new 
list in sorted order (which is what the new-in-2.4 sorted() 
builtin does).
msg47370 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-12-06 17:49
Logged In: YES 
user_id=80475

Sorry, the patch is not right.  In-place is meant to
communicate thet the original list is mutated.  Contrast
that with the behavior of sorted() which leaves the original
intact.

Perhaps you are thinking in terms of heapsort which is
in-place and requires no additional auxiliary storage. 
While that is not true for the current algorithm, we do not
document or make promises about the memory requirements --
that is considered to be an implementation detail that is
subject to change.
msg47371 - (view) Author: Heikki Orsila (shd) Date: 2004-12-07 13:39
Logged In: YES 
user_id=6941

My bad. Sorry for misunderstanding the meaning of in-place.
History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41286
2004-12-06 17:15:26shdcreate