sorting dictionary keys?
From: John Smith (asdf_at_asdf.com)
Date: 11/29/03
- Next message: Jay O'Connor: "Re: sorting dictionary keys?"
- Previous message: Anders Eriksson: "SGMLParser eats ä etc"
- Next in thread: Jay O'Connor: "Re: sorting dictionary keys?"
- Reply: Jay O'Connor: "Re: sorting dictionary keys?"
- Reply: Emile van Sebille: "Re: sorting dictionary keys?"
- Reply: Kristian Ovaska: "Re: sorting dictionary keys?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 16:44:18 -0500
Hi, what's the fastest way (least amount of typing) to sort dictionary
objects by the key? What's the fastest way of iterating over sorted keys
for a dictionary in terms of performance? Are the two equivalent?
The way I have been doing it is:
d = {}
#populate d
keys = d.keys()
keys.sort()
for k in keys:
print k, d[k]
but I would like to do:
#error here
for k in d.keys().sort():
print k, d[k]
why doesn't the nested function call work? Thanks in advance.
- Next message: Jay O'Connor: "Re: sorting dictionary keys?"
- Previous message: Anders Eriksson: "SGMLParser eats ä etc"
- Next in thread: Jay O'Connor: "Re: sorting dictionary keys?"
- Reply: Jay O'Connor: "Re: sorting dictionary keys?"
- Reply: Emile van Sebille: "Re: sorting dictionary keys?"
- Reply: Kristian Ovaska: "Re: sorting dictionary keys?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|