Rita Sue and Bob too

Shane Holloway (IEEE) shane.holloway at ieee.org
Sun Aug 22 19:28:33 EDT 2004


> You can do it with list List Comprehensions:
> 
> BigList = ['Jean', 'Eric', 'Remy', 'Anne', 'Denis', 'Alain', 'Armel',
> 'Louis']
> SmallList = ['Eric', 'Denis', 'Georges', 'Jean']
> 
> if ( [x for x in SmallList if x in BigList] == SmallList ):
>    print "They were found"
> else:
>    print "They are not in list"
> 
> 
> [x for x in SmallList if x in BigList] evaluates to a list with common
> elements of SmallList and BigList

A little change:

   Difference = [x for x in SmallList if x not in BigList]
   if not Difference:
     print "They were found"
   else:
     print Difference, "were not found in the list"





More information about the Python-list mailing list