Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = {1:'', 2:'', 3:'', 4:''}
- exclusion = [3, 4, 5]
- # have to build up a new list or the iteration breaks
- toRemove = []
- for var in a.iterkeys():
- if var in exclusion:
- toRemove.append(var)
- for var in toRemove:
- del a[var]
- for key in exclusion:
- a.pop(key, None)
- a = dict((key,value) for (key,value) in a.iteritems() if key not in exclusion)
- exclusion = set([3, 4, 5])
- for key in exclusion.intersection(a):
- del a[key]
Add Comment
Please, Sign In to add comment