-1

Write a Python program to sort a list of dictionaries using Lambda

device_models = [{'make':'Asus', 'model':216, 'color':'Black'}, {'make':'NOKIA', 'model':'2', 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}]
Cprk Praveen
  • 129
  • 1
  • 10
  • This isn't a question... Asking a question that literally no one could you could provide an answer to you *but* you (given the complete lack of criteria for a useful answer) is not helpful. – ShadowRanger Jun 22 '20 at 13:35

1 Answers1

-1
device_models = [{'make':'Asus', 'model':216, 'color':'Black'}, {'make':'NOKIA', 'model':'2', 'color':'Gold'}, {'make':'Samsung', 'model': 7, 'color':'Blue'}]
print("Original list of dictionaries :")
print(device_models)
# to sort a list of dictionaries using Lambda
sorted_models = sorted(device_models, key = lambda x: x['color'])
print("\nSorting the List of dictionaries :")
print(sorted_models)

O/P:-

Original list of dictionaries :
[{'make': 'Asus', 'model': 216, 'color': 'Black'}, {'make': 'NOKIA', 'model': '2', 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]

Sorting the List of dictionaries :
[{'make': 'Asus', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'NOKIA', 'model': '2', 'color': 'Gold'}]
Cprk Praveen
  • 129
  • 1
  • 10