Created
April 13, 2020 02:34
-
-
Save ahmedazizkhelifi/980d53e3d15a6f9b749bc384bc1e6a42 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
| # 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