-5

How can i do this:

In:

a = [{'10100': u'Z'}, {u'00101': u'C'}, {u'01100': u'B'}, {u'00111': u'T'}]

Out:

a = [{u'01100': u'B'}, {u'00101': u'C'}, {u'00111': u'T'}, {'10100': u'Z'}]

I mean in order to value

1 Answers1

0

You can use dict.values() in the sorting key:

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])

Output:

[{u'01100': u'B'}, {u'00101': u'C'}, {u'00111': u'T'}, {'10100': u'Z'}]
Ajax1234
  • 69,937
  • 8
  • 61
  • 102