Skip to content

Instantly share code, notes, and snippets.

@ahmedazizkhelifi
Created April 13, 2020 02:34
Show Gist options
  • Save ahmedazizkhelifi/dfdc8c3428c2aa376bf450f8ba0d85cc to your computer and use it in GitHub Desktop.
Save ahmedazizkhelifi/dfdc8c3428c2aa376bf450f8ba0d85cc to your computer and use it in GitHub Desktop.
# 1) conventional syntax:
dict1={}
for user in Users:
dict1.update({user['name']:user['salary']})
print (dict1) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}
# 2) Dict comprehesion:
dict2 = {user['name'] : user['salary'] for user in Users }
print(dict2) #>>> {'Ahmed': 1200, 'Aziz': 1800, 'Khelifi': 820}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment