This is probably not very efficient, but you could use:
In [1]: a = [1,3,2,2,2]
In [2]: b = [1,3,2]
In [3]: b == [val for val in a if val in b]
Out[3]: False
In [4]: a = [6,1,3,2,5,4]
In [5]: b == [val for val in a if val in b]
Out[5]: True
The first test returns False because of the duplicates of 2
. The question is how you want to deal with duplicates in general. If you only want to cut them off at the end then you could trim the list to the length of a
:
In [6]: a = [1,3,2,2,2]
In [7]: b == [val for val in a if val in b][:len(b)]
Out[7]: True