there are 4 dictionaris in a list:
mylist = [{'name': 'c', 'age': 21}, {'name': 'b', 'age': 20}, {'name': 'd', 'age': 21}, {'name': 'a', 'age': 20}]
if I want to sort this by age, then I should use:
mylist.sort(key= lambda psn: psn['age'])
then output would be:
mylist = [{'name': 'b', 'age': 20}, {'name': 'a', 'age': 20}, {'name': 'c', 'age': 21}, {'name': 'd', 'age': 21}]
now! what if i want to sort this list by 'age' but if there were any same ages, then i sort just those persons by name ? in this list, 'a' and 'b' have same ages. and also 'c' and 'd' have same ages too. so how can i sort this list by 'age' but if there were any same ages sort them by 'name' ? (alphabetically)
should be this:
mylist = [{'name': 'a', 'age': 20}, {'name': 'b', 'age': 20}, {'name': 'c', 'age': 21}, {'name': 'd', 'age': 21}]