I've changed the functions to be methods.

I don't understand your point regarding sets. Sets aren't ordered, but they're iterable, and order isn't necessary here. I just used sets to ensure there aren't duplicates. Could you clarify?