Comprehensions for Sets and Dictionaries in Python


Similar to list comprehensions, but for sets and dictionaries.

Source Code

# Set comprehension
squared_set = {x**2 for x in range(10)}

# Dictionary comprehension
squared_dict = {x: x**2 for x in range(10)}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments