Ask Question
19 March, 04:29

Given a dictionary d and a list lst, remove all elements from the dictionary whose key is an element of lst. For example, given the dictionary {1:2, 3:4, 5:6, 7:8} and the list [1, 7], the resulting dictionary would be {3:4, 5:6}. Assume every element of the list is a key in the dictionary.

+1
Answers (1)
  1. 19 March, 04:39
    0
    d = {1:2, 3:4, 5:6, 7:8}

    list = [1, 7]

    not_found = set ()

    for x in list:

    if x not in d. keys ():

    not_found. add (x)

    else:

    del d[x]

    print (d)

    print (not_found)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given a dictionary d and a list lst, remove all elements from the dictionary whose key is an element of lst. For example, given the ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers