-2

I am trying to check if shorter tuples are contained inside a longer one, but I need the order in which things are placed in the larger tuple to be respected during the checking. Here is an example:

A = ('A', 'B', 'C')
B = ('A', 'B')
C = ('A', 'C')
set(B).issubset(A)
set(C).issubset(A)

My expectation is set(B).issubset(A) to return True (as it is), but set(C).issubset(A) should return False. Is there a way to do this without a tedious for loops?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
em07
  • 1

1 Answers1

0

as stated in the comments: this makes no sense as "sets'.

However, if all your elements are strings, the behavior of the "in" operator for strings may be enough for you. In order for it work you can join your tuples in a single string and then check with "in":

"".join(B) in "".join(A)

will yield your desired outputs. The drawback is if your strings can give you false positives, for example in:

A = ("AB", "C")
B = ("B", "C")

will give you a match - if that is a possibility, even a remote one, you will have to implement a manual search with a for loop and some state variables.

jsbueno
  • 99,910
  • 10
  • 151
  • 209