Skip to content

Instantly share code, notes, and snippets.

@bergpb
Last active December 20, 2018 11:02
Show Gist options
  • Save bergpb/4c44e5b24670a622baa8679dc187552f to your computer and use it in GitHub Desktop.
Save bergpb/4c44e5b24670a622baa8679dc187552f to your computer and use it in GitHub Desktop.
Python dict comprehensions.
# 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