Skip to content

Instantly share code, notes, and snippets.

@ahmedazizkhelifi
Created April 13, 2020 02:21
Show Gist options
  • Save ahmedazizkhelifi/9908031f534cf9c21521e2f0e89b0af0 to your computer and use it in GitHub Desktop.
Save ahmedazizkhelifi/9908031f534cf9c21521e2f0e89b0af0 to your computer and use it in GitHub Desktop.
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