J
John Smith
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.
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.