I got the following error
AttributeError: 'NoneType' object has no attribute 'add'
while I tried this.
not_yet_bought_set = set()
.
.
.
for value in set_dict.itervalues():
for item in value:
not_yet_bought_set = not_yet_bought_set.add(item)
I dont't get why I got this error, is it because I always make not_yet_bought_set new? I make this, because when I only do
not_yet_bought_set.add(item)
there wont be all the items from all values. I do not know why.
value are sets and
not_yet_bought_set.union(value)
also generate this error
Thanks for any help.
set.add
returns nothing.Replace following line:
with:
this will return
None
and you are assigning it tonot_yet_bought_set
. So,not_yet_bought_set
becomesNone
now. The next timeis executed,
add
will be invoked onNone
. Thats why it fails.To fix this, simply do this. Dont assign this to anything.