dictionary = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
list1 = [zero, one, two]
I want to delete the entry '3:three' from the dictionary since it is not in the list. I am retaining only the common entries in the list. How can I do it???
How to compare list and dictionary in Python???
Re: How to compare list and dictionary in Python???
Syntax: Select all
dictionary = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
list1 = ['zero', 'one', 'two']
for key, value in tuple(dictionary.items()):
if value not in list1:
del dictionary[key]
print(dictionary)
Return to “General Discussion”
Who is online
Users browsing this forum: No registered users and 25 guests