s.union(r) is a new set with elements from both s and r.reference You need to change
s.union(r)
to
s = s.union(r)
or, use set.update.
s.union(r) is a new set with elements from both s and r.reference You need to change
s.union(r)
to
s = s.union(r)
or, use set.update.