-
-
Save H3lllfir3/4c769f513675f2f2bdaf7b61ef61141c to your computer and use it in GitHub Desktop.
Dictionary Comprehension
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
| >>> numbers = {num:num ** 2 for num in range(5)} | |
| >>> numbers | |
| {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} | |
| >>> numbers = {x:x ** 2 for x in [1, 2, 3, 4, 5, 6] if x % 2 == 0} | |
| >>> numbers | |
| {2: 4, 4: 16, 6: 36} | |
| >>> names = ['ayoub', 'reza', 'mersad'] | |
| >>> names = {f:f.capitalize() for f in names} | |
| {'ayoub': 'Ayoub', 'reza': 'Reza', 'mersad': 'Mersad'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment