sorting dictionary keys?

Kristian Ovaska kristian.ovaska at helsinki.fi
Sun Nov 30 09:09:00 EST 2003


"John Smith" <asdf at asdf.com>:
>Hi, what's the fastest way (least amount of typing) to sort dictionary
>objects by the key?

You could use a custom dictionary that does what you want.

class Mydict(dict):
    def sortedkeys(self):
        k = self.keys()
        k.sort()
        return k

-- 
Kristian Ovaska - http://www.cs.helsinki.fi/u/hkovaska/




More information about the Python-list mailing list