Test if list contains another list

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Sep 9 04:49:18 EDT 2008


Matimus a écrit :
> On Sep 8, 12:32 am, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
(snip)
>>  >>> set(a).issubset(set(b))
>> True
>>  >>>
>> 
> Just to clarify, doing it using sets is not going to preserve order OR
> number of elements that are the same.
> 
> That is:
> 
>>>> a = [1,1,2,3,4]
>>>> b = [4,5,3,7,2,6,1]
>>>> set(a).issubset(set(b))
> True
> 
> This will return True if b contains at least on of each element found
> in a. If the OP wanted to check that list `a` appeared in order
> somewhere in list `b` then sets won't work.

Indeed, and I should have mentionned this myself. Thanks for this reminder.




More information about the Python-list mailing list