I want to test if an ordered set is a subset of a bigger ordered set. I used tuples and itertools.combinations:
def subset_test(a, b):
return a in itertools.combinations(b, len(a))
For instance,
>>> subset_test((0, 1, 2), (0, 3, 1, 4, 2))
True
>>> subset_test((0, 1, 2), (0, 3, 2, 4, 1))
False
It works, but is slow when I test big tuples.
list, you can check membership in a generator too and it will save one run through the combinations. - jamylak