How to test if one dict is subset of another?

Paul Rubin http
Tue Feb 20 12:44:01 EST 2007


"Jay Tee" <jeff.templon at gmail.com> writes:
> >>> l1= [3, 4, 7, 2]
> >>> l2 = [2, 3]
> >>> l2 = [2, 3, 99]
> >>> l1 & l2
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: unsupported operand type(s) for &: 'list' and 'list'
> 
> what am I missing?

They are sets, not lists.

   from sets import Set as set  # use in 2.3 and earlier

   l1= set([3, 4, 7, 2])
   l2 = set([2, 3])
   l2 = set([2, 3, 99])
   print l1 & l2



More information about the Python-list mailing list