2021年4月28日星期三

How to check if a list (string) contains another list (string) considering order

I have two list (or string): one is big, and the other one is small. I want to check whether the bigger one (A) contains the small one (B) or not.

My expectation is as follows:

Case 1. B is a subset of A

A = [1,2,3]  B = [1,2]   contains(A, B) = True  

Case 2. B is not a subset of A, but order [1,2] is maintained in A

A = [1,3,2]  B = [1,2]  contains(A, B) = True  

Case 3. False because 4 in not A

A = [1,3,2]  B = [1,4]  contains(A, B) = False  

Case 4. False because the order [2,1] not maintained in A, even though A contains 1 and 2.

A = [1,3,2]  B = [2,1]  contains(A, B) = False  

A and B could be string.

https://stackoverflow.com/questions/67310223/how-to-check-if-a-list-string-contains-another-list-string-considering-order April 29, 2021 at 10:25AM

没有评论:

发表评论