Dcrielaard
6/22/2019 - 8:45 PM

Selective removal in dictionary

Removing items in a dictionary

dict = {('Ghostbusters', 2016): 5.4, ('Ghostbusters', 1984): 7.8, ('Cars', 2006): 7.1}

to_remove = []

for i in dict:
    if(i[1] < 2000):
        to_remove.append(i)

for i in to_remove:
    dict.pop(i)
    
dict