我该怎么做:
在:
a = [{'10100': u'Z'}, {u'00101': u'C'}, {u'01100': u'B'}, {u'00111': u'T'}]
输出:
a = [{u'01100': u'B'}, {u'00101': u'C'}, {u'00111': u'T'}, {'10100': u'Z'}]
我的意思是为了重视
答案 0 :(得分:0)
您可以在排序键中使用dict.values()
:
a = [{'10100': u'Z'}, {u'00101': u'C'}, {u'01100': u'B'}, {u'00111': u'T'}]
new_a = sorted(a, key=lambda x:x.values()[0])
输出:
[{u'01100': u'B'}, {u'00101': u'C'}, {u'00111': u'T'}, {'10100': u'Z'}]