I have a list full of variable names and a dictionary with names and their ID's.
Example:
name=['name1','name2'....'name20']
dicti={'1':'name1', '2':'name2','hello':'world",'animal':'dog',...'20':'name20'}
What i want is to search the dictionary with elements from the list. If the list element exist in dictionary then don't delete it.
I got this code
for i in dicti.values() :
for j in name :
if j != i :
del dicti[i]
else :
continue
When i run the code i got this error:
KeyError: 'name1'
and it cannot delete the element i want.