How can I check to see if an exact match of B appears in A in the same consecutive order? In the below example 99, 3, 2 are in A in that exact way :
A = [0, 3, 123, 0, 99, 3, 2, 1, 2, 33, 1, 76]
B = [99, 3, 2]
An example of A which would fail is :
A = [0, 321, 99, 0, 3, 0, 2, 0]
As 99, 3, 2 elements do not appear consecutively.
I have tried doing :
if B in A:
print("yes")
else:
print("NO")
This fails.
Thank you all, Jemma
def consecutive_in(B,A):
return B in (A[i:i+len(B)] for i in range(len(A)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With