1
Hualin 2013 年 5 月 16 日 keys = sorted(block_info.__dict__.keys())
for key in keys: sort_block_info.append([key, getattr(block_info, key)]) 不知道这段代码对你没用。前提是你的 dict 的 key 命名的字母序是有意义的。比如叫 field1 field2... |
2
SErHo 2013 年 5 月 16 日 |
3
yegle 2013 年 5 月 20 日 |
4
Livid MOD PRO |
5
monkeylyf 2013 年 5 月 20 日
OrderedDict + 1
|
6
hhrmatata 2013 年 5 月 20 日
python 2.7+支持collections.OrderedDict
|
7
ruoran OP |
8
DH 2013 年 5 月 20 日
看你的key是什么样的,还有你的具体需求。排序的话,
可以用 heapq h = [] heappush(h, ('key8', 'write code')) heappush(h, ('key1', 'release product')) heappush(h, ('key3', 'write spec')) heappush(h, ('key6', 'create tests')) heappop(h) # ('key1', 'release product') heappop(h) # ('key3', 'write spec') heappop(h) # ('key3', 'write spec') heappop(h) # ('key8', 'write code') |
9
DH 2013 年 5 月 20 日
还可以用 bisect
h = [] bisect.insort_left(h, ('key1', 'test')) bisect.insort_left(h, ('key2', 'test')) bisect.insort_left(h, ('key0', 'test')) h # [('key0', 'test'), ('key1', 'test'), ('key2', 'test')] |
10
reusFork 2013 年 5 月 20 日 via Android
用heap
|