0
temp = [{'name':'abcd3', "id":3},
        {'name':'abcd', "id":1},
        {'name':'abcd4', "id":4},
        {'name':'abcd2', "id":2},]

How to sort temp using id.

Faisal Maqbool
  • 107
  • 1
  • 7
chetan
  • 117
  • 1
  • 12

1 Answers1

0

You sort by using the sort method on the object. ie

temp.sort()

Solution which is none destructive or does not mutate object use

sorted(temp,key=lambda x:x['id'])