You can use dictionary comprehension :

Say :
dict1 = {'a': 123, 'b': 456}
set1 = {'a'}

intersection :
>>> { key:dict1[key] for key in dict1 if key in set1 }
{'a': 123}

difference :
>>> { key:dict1[key] for key in dict1 if not key in set1 }
{'b': 456}

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to