Answer the question
In order to leave comments, you need to log in
How to check if one list exists in another?
I have a list a=[1,2,6]
and there is a list b it can be equal to [2,6,1], or [1,5,6,2], or the same [1,2,6]
as check whether the NUMBERS (i.e., the order does not matter) of the list a are included in the list b?
Answer the question
In order to leave comments, you need to log in
>>> a=[1,2,6]
>>> b1=[2,6,1]
>>> b2=[1,5,6,2]
>>> b3=[1,2,6]
>>> b4=[1,2,8]
>>>
>>> all(x in b1 for x in a)
True
>>> all(x in b2 for x in a)
True
>>> all(x in b3 for x in a)
True
>>> all(x in b4 for x in a)
False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question