how to sort a hash list without generating a new object?

S

smith jack

the source code is as follows

x={}
x['a'] = 11
x['c'] = 19
x['b'] = 13
print x

tmp = sorted(x.items(), key = lambda x:x[0]) # increase order by
default, if i want to have a descending order, what should i do?
# after sorted is called, a list will be generated, and the hash list
x is not changed at all, how to convert x to a sorted hash list
without generating a new object?
print tmp
print x
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top