@Cow I don't Python. But I'd expect that it would be optimised so it doesn't re-create the set all the time. There is a well-known compiler optimisation called
Loop-invariant code motion which transforms a loop to pull unnecessary calculations out of it. E.g.
for (int i = 0; i < something.length; i++)
will optimise the access to
something.length
to be essentially
int length = something.length; for (int i = 0; i < length; i++)