News for hackers. Stuff that matters.
Re:Improving your (Python) code with modern idioms by dbecker on Tuesday May 08, 2012 @01:50AM (#3942428)
The benefit is only lost if you want to store the sorted mylist.

However, sorted() is useful if you want to create a list, sort it, use it, and throw it away... all in a single line.

The blog gives an example where a file is read, sorted and transformed. If he loaded the file to a list and sorted that list before transforming it, there would be an unnecessary copy of the list sitting around consuming memory.

There are no comments on this comment yet.