I have a dictionary with names as key and (age, Date of Birth) tuple as the value for those keys. E.g.
dict = {\'Adam\' : (10, \'2002-08-13\'),
\'Eve
The usual way is to create a new dictionary containing only the items you want to keep:
new_data = {k: v for k, v in data.iteritems() if v[0] <= 30}
In Python 3.x, use items()
instead of iteritems()
.
If you need to change the original dictionary in place, you can use a for
-loop:
for k, v in data.items():
if v[0] > 30:
del data[k]
In Python 3.x, use list(data.items())
instead of data.items()
.