
1 Hualin 2013-05-16 09:04:36 +08:00 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-05-16 09:11:00 +08:00 |
3 yegle 2013-05-20 02:56:24 +08:00 |
4 Livid MOD PRO |
5 monkeylyf 2013-05-20 03:31:43 +08:00 OrderedDict + 1 |
6 hhrmatata 2013-05-20 09:19:29 +08:00 python 2.7+支持collections.OrderedDict |
7 ruoran OP |
8 DH 2013-05-20 09:42:13 +08:00 看你的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-05-20 09:47:06 +08:00 还可以用 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-05-20 12:00:53 +08:00 via Android 用heap |