[Klaus Alexander Seistrup] > >>> d1 = {1:'a', 2:'b', 3:'c', 4:'d', 5:'e'} > >>> s1 = set(d1) > >>> s1 > set([1, 2, 3, 4, 5]) > >>> s2 = set([1, 3, 5]) > >>> s1-s2 > set([2, 4]) > >>> for k in s1-s2: > ... del d1[k] > ...
FWIW, if s2 is not already a set object, it need not be transformed before using it. Instead, write: for k in set(d1).difference([1,3,5]): del d1[k] If you prefer to work with dictionaries instead of sets, then adapt the existing code for symmetric_difference_update() in sets.py. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list