-1

Suppose that I am having a dictionary as the following.

new_vocd = {'amazon': [668], 'flipkart': [34,56], 'myntra': [78,89,98], 'ebay': [876,768], 'microsoft': [67]}

I am having a exclude set with the following format.

exclude = {'amazon', 'microsoft'}

I want to exclude the words from new_vocd dictionary that are present in the exclude set. Is it possible using set difference option?

What are the other available ways? Any help is appreciated.

Expected output in terms of dictionary:

new_vocd = {'flipkart': [34,56], 'myntra': [78,89,98], 'ebay': [876,768]}
M S
  • 894
  • 1
  • 13
  • 41

2 Answers2

1
new_vocd = {'amazon': [668], 'flipkart': [34, 56], 'myntra': [78, 89, 98], 'ebay': [876, 768], 'microsoft': [67]}
exclude = {'amazon', 'microsoft'}
for i in exclude:
    new_vocd.pop(i)
print(new_vocd)
Kostas Charitidis
  • 2,991
  • 1
  • 12
  • 23
1
new_vocd = {k:v for k, v in new_vocd.items() if k not in exclude}
ComplicatedPhenomenon
  • 4,055
  • 2
  • 18
  • 45