Let's say I have two sets:
s1 = {1, 2, 3, 4, 5}
s2 = {4, 5, 6, 7, 8}
I want to split s1
into {4, 5}
and {1, 2, 3}
, where the first part is an intersection of s1
and s2
, and the second part is the remainder.
I can do it like this:
part1 = s1.intersection(s2)
part2 = s1.difference(s2)
But it seems to me that this way I'll perform quite the same operation twice, which can take a long while on big sets. Can I do it with one operation in Python? I want to do something like
part1, part2 = slit_sets(s1, s2)