|
5
|
Python 2.4 adds a new builtin function sorted(), which can make obtaining the items of a dictionary sorted by key or value a single line operation.
The new 'sorted' builtin is a convenient expression replacement for the old statement based approach to obtaining a sorted copy. The new keyword arguments to the sort operations are extremely handy for tasks such as sorting a dictionary by value (see the "Sort names and separate by last initial" recipe for a more involved use of the new features)
Tags: search
|
3 comments
Add a comment
Sign in to comment
Download
Copy to clipboard

not a dictionary. note that the example creates a list, not a dictionary.
I'm not sure how new this feature is, but in Python 2.5 i use this:
Uh, yeah... Since the goal was to get something that's ordered, a list makes sense.