Reputation: 532
I would like to create an empty set in Python.
I tried set1 = set()
as mentioned here.
However I get the error:
set1 = set()
TypeError: 'dict' object is not callable
How can I create an empty set in Python?
Upvotes: 3
Views: 1608
Reputation: 11
I get the same error while not having any already declared foo before declaring with foo = set()
.
From this answer, it works for me using an emty tuple, like so :
foo = {*()}
Upvotes: 1
Reputation: 196
Unfortunately foo = set()
is the right way to declare empty set in both python 2 and python 3.
I guess you have a set = {}
in the former lines.
You can try print(type(set))
to check it.
Upvotes: 2