So I was give the task to write a code to get the union of two sets. And i wrote the the following 2 versions of codes.
Version 1
###### Set_Input ########
set_1 = input().split(" ")
set_2 = input().split(" ")
set_union = set_1 + set_2
###### Set_Union_Logic ########
for i in set_union:
if set_union.count(i)>1:
set_union.remove(i)
print(set_union)
Version 2
###### Set_Input ########
set_1 = input().split(" ")
set_2 = input().split(" ")
set_union = set_1 + set_2
###### Set_Union_Logic ########
for i in set_union:
if set_union.count(i)>1:
set_union= set_union.remove(i)
print(set_union)
Version 1 works fine but Version 2 gives me the following error
if set_union.count(i)>1:
AttributeError: 'NoneType' object has no attribute 'count'
Can any one explain why writing set_union= set_union.remove(i) in the loop causes this error. Thanks in advance.