Last active
December 20, 2018 11:02
-
-
Save bergpb/4c44e5b24670a622baa8679dc187552f to your computer and use it in GitHub Desktop.
Python dict comprehensions.
This file contains 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
# dict comprehensions | |
list = [1,2,3,4,5,6,7,8,9,10] | |
doubles_of_odds_dict = {'number_'+str(i):i*2 for i in list if i%2} | |
doubles_of_odds_dict | |
# out: {'number_1': 2, 'number_3': 6, 'number_5': 10, 'number_7': 14, 'number_9': 18} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment