Test if list contains another list

Christian Heimes lists at cheimes.de
Mon Sep 8 05:28:12 EDT 2008


mathieu wrote:
> Hi there,
> 
>   I am trying to write something very simple to test if a list
> contains another one:
> 
> a = [1,2,3]
> 
> b = [3,2,1,4]
> 
> but 'a in b' returns False. How do I check that a is indeed contained
> in b ?

Use sets:

 >>> a = [1,2,3]
 >>> b = [3,2,1,4]
 >>> set(a).issubset(set(b))
True


Christian




More information about the Python-list mailing list