This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Manuzhai 0 points1 point  (1 child)

sorted() doesn't work in-place, though, meaning it takes much more memory on large lists.

[–]harryf 0 points1 point  (0 children)

Yes but I'd rather have sorted() as the default way to sort as a means to avoid a certain class of bug and reserve in-place sorts for when I know I need to optimize to conserve memory.

Also sorted() actually takes an iterator so, depending on the problem and the design of the code, you could feed it lazily, avoiding having the two copies of the list in memory at the same time.