Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10753
| Date | 2011-08-03 02:02 +0800 |
|---|---|
| Subject | how to sort a hash list without generating a new object? |
| From | smith jack <thinke365@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1795.1312308133.1164.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
how to sort a hash list without generating a new object? smith jack <thinke365@gmail.com> - 2011-08-03 02:02 +0800
csiph-web