-
-
Save DugalMcCrow/cff86648e8c36c47ebbe9054d4acf3e6 to your computer and use it in GitHub Desktop.
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
>>> # Dictionary comprehension | |
>>> squares_dict = {number: number*number for number in numbers} | |
>>> squares_dict | |
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36} | |
>>> | |
>>> # Set comprehension | |
>>> numbers_dups = [1, 2, 3, 4, 3, 2, 1] | |
>>> squares_set = {number*number for number in numbers_dups} | |
>>> squares_set | |
{16, 1, 4, 9} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment