-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsorting.py
25 lines (23 loc) · 1.17 KB
/
sorting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
if __name__ == '__main__':
countries_population = [
{"country": "China", "population": 1444216107},
{"country": "India", "population": 1393409038},
{"country": "United States", "population": 332915073},
{"country": "Indonesia", "population": 276361783},
{"country": "Pakistan", "population": 225199937},
{"country": "Brazil", "population": 213993437},
{"country": "Nigeria", "population": 211400708},
{"country": "Bangladesh", "population": 166303498},
{"country": "Russia", "population": 145912025},
{"country": "Mexico", "population": 130262216},
]
animals = ["Dog", "Cat", "Elephant", "Lion", "Giraffe",
"Monkey", "Penguin", "Kangaroo", "Dolphin", "Tiger"]
animals_sorted_by_name_len = sorted(animals, key=len)
countries_sorted_by_population_desc = sorted(
countries_population, key=lambda x: x['population'], reverse=True)
countries_sorted_by_country_name_len = sorted(
countries_population, key=lambda x: len(x['country']))
print(animals_sorted_by_name_len)
# print(countries_sorted_by_population_desc)
# print(countries_sorted_by_country_name_len)