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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…