With Python 2.7, you have dict.viewitems() which will provide you with behavior similar to a set. (Oh, you seem to be using Py3, since you have dict_items() objects!)
So you can use
a = dict(a=1) b = dict(a=1, c=3) ai = a.viewitems() # items() on 3.x bi = b.viewitems() # items() on 3.x ai - bi # gives a set([]) bi - ai # gives a set([('c', 3)]) ai & bi # gives ai ai | bi # gives bi
As you want to make sure that each element of a also contained in b , you need
ai & bi == ai
If this is not the case, a does not contain the element a , <disturbing " & .
EDIT: But it's even easier - just
ai <= bi
as you could do on the set.
source share