Created
April 13, 2020 02:21
-
-
Save ahmedazizkhelifi/9908031f534cf9c21521e2f0e89b0af0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Users= [ | |
{'id' : 0, 'name' : 'Ahmed', 'salary' : 1200}, | |
{'id' : 1, 'name' : 'Aziz', 'salary' : 1800}, | |
{'id' : 2, 'name' : 'Khelifi', 'salary' : 820} | |
] | |
#conventional syntax: | |
users_name=[] | |
for user in Users: | |
users_name.append(user['name']) | |
print(users_name) #>>> ['Ahmed', 'Aziz', 'Khelifi'] | |
#comprehension list: | |
users_name2 =[ user['name'] for user in Users] | |
print(users_name2) #>>> ['Ahmed', 'Aziz', 'Khelifi'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment