[Tutor] Sorting a dictionary in one line?

Terry Carroll carroll@tjc.com
Sun Jan 19 16:24:02 2003


On Sun, 19 Jan 2003, Terry Carroll wrote:

> 1) Why doesn't this work? If I understand this right, dict.keys() returns
> a list, and lists have a sort() method, which returns a list, which is a
> sequence; so why is this an iteration over a non-sequence?

Okay, I found my flaw here: sort() doesn't return a ListType object -- it
returns a NoneType object.

Still, out of curiosity:

> 2) Not that it's important to do this in one line, but is it possible?

Or, put another way, is it possible to operate on an anonymously sorted
list (e.g., dict.keys().sort() )?

-- 
Terry Carroll        |
Santa Clara, CA      |   "The parties are advised to chill."
carroll@tjc.com      |       - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est  |         no. 98-56577 (9th Cir. July 24, 2002)