Comprehensions for Sets and Dictionaries in Python


Generate sets and dictionaries with comprehension syntax.

Source Code

squared_set = {x**2 for x in range(-3, 4)}
print(squared_set)

invert_dict = {value: key for key, value in squared_dict.items()}
print(invert_dict)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments