News for hackers. Stuff that matters.
Re:Improving your (Python) code with modern idioms by tetha on Tuesday May 08, 2012 @06:24AM (#3942995)
He doesn't do a clean comparision.

If you have a list of data and need this data in a specific order and coincidentially iterate over this list every once in a while, then sorted will be less efficient, because you can sort in-place once.

If you have a list of data and you want to iterate over it in a specific order just this single time, you will need to spend a linear amount of memory to sort the list and then iterate over it.

In the first case, sorted() is not useful, because .sort() sorts in-place without additional memory overhead. In the second case, copy/.sort is required and just requires more code for pretty much the same effect. In this case, sorted() is just as bad as the alternative, but shorter.

There are no comments on this comment yet.