I have a variable with n words, separated by whitespaces. str.split()
returns a list
of these words, which is then converted to a tuple
with tuple()
, which is finally converted to a frozenset
and added to the set
of frozensets
. For some reason this returns:
TypeError: 'builtin_function_or_method' object is not subscriptable
my code:
set = set([])
str = 'a b c d'
set.add[frozenset(tuple(set.split()))]
problems already addressed :
set
of sets`frozenset
out of lists
.append
instead of .add
(Btw this is my first question on stack overflow)
first, you should not name your vars with reserved names/built-ins. then, set.add
is a function, use parens not brackets. and finally you don't need the tuple
step.
my_set = set()
my_set.add(frozenset('a b c d'.split()))