FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonprojects/sort-a-list-python at main · Spacecoder19/pythonprojects · GitHub
Spacecoder19
pythonprojects
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonprojects
/
sort-a-list-python
Copy path
More file actions
More file actions
Latest commit
History
History
History
19 lines (16 loc) · 590 Bytes
Breadcrumbs
pythonprojects
/
sort-a-list-python
Copy path
File metadata and controls
19 lines (16 loc) · 590 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# sorting using custom key
employees = [
{'Name': 'Piyush', 'age': 25, 'salary': 10000},
{'Name': 'Shweta', 'age': 30, 'salary': 8000},
{'Name': 'John Cena', 'age': 18, 'salary': 1000},
{'Name': 'Masoom', 'age': 40, 'salary': 15000},
]
# sort by name (Ascending order)
employees.sort(key=lambda x: x.get('Name'))
print(employees, end='\n\n')
# sort by Age (Ascending order)
employees.sort(key=lambda x: x.get('age'))
print(employees, end='\n\n')
# sort by salary (Descending order)
employees.sort(key=lambda x: x.get('salary'), reverse=True)
print(employees, end='\n\n')
Back
|
FazBrowse Home
|
New Git URL