- 论坛徽章:
- 0
|
本帖最后由 jokimina 于 2015-09-01 14:53 编辑
比如:
{'a':1,'b':2,'c:3','d':4} 按照
b,c,a,d 这种无规律进行排列要怎么处理
bcad这个顺序是自己手动指定, 而非条件判断的..
定义的顺序列表:['it_id','it_user','it_type','it_dep','it_size','it_serial','it_status','it_brand','it_cost','it_reason','it_buytime','it_channel','it_ip','it_dec']
数据样例(列表嵌套的字典,这里是列表中的一个):
[
{'it_brand': u'HP',
'it_type': u'\u663e\u793a\u5668',
'it_channel': u'\u7a7a',
'it_ip': u'\u7a7a',
'it_dec': u'\u7a7a',
'it_dep': u'\u884c\u653f\u4eba\u4e8b',
'it_status': u'\u4f7f\u7528\u4e2d',
'it_user': u'\u5f20\u601d\u601d',
'it_serial': u'SHJDLE001',
'it_size': u'P221',
'it_reason': u'\u529e\u516c',
'it_id': 695L,
'it_cost': u'\u7a7a', 'it_buytime': None}
]
自己的笨方法.. 错得妥妥的. = =
sortFlied = ['it_id','it_user','it_type','it_dep','it_size','it_serial','it_status','it_brand','it_cost','it_reason','it_buytime','it_channel','it_ip','it_dec']
sortedList = []
for n in range(len(mysql_result)):
sortedList.append({})
for flied in sortFlied:
sortedList[n][flied] = mysql_result[n][flied]
然而字典并不是按照插入顺序排序的..........
已经解决......... 请无视该贴 = =
|
|