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
  • 121
  • 1
  • 8
chetan
  • 129
  • 2
  • 12

1 Answers1

1

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

Alfred Ayi-bonte
  • 715
  • 7
  • 11