159k views
1 vote
Given a dictionary d and a list lst, remove all elements from the dictionary whose key is an element of lst. Any elements from the list that are NOT keys of the dictionary should be added to a new set associated with the variable not_found. For example, given the dictionary {1:2, 3:4, 5:6, 7:8} and the list [1, 6, 7], the resulting dictionary would be {3:4, 5:6} and the set not_found would contain 6. Use Python

User Redab
by
4.6k points

1 Answer

4 votes

Answer:

the code is attached

Step-by-step explanation:

  1. I defined a function called operation
  2. the function accepts two parameters d as dictionary and lst as a list
  3. I defined an empty set not_found
  4. for all elements in the list lst
  5. if the element is a key in dictionary I delete the key value pair in the dictionary
  6. if not I add the element to the set
  7. the function returns d and not_found
Given a dictionary d and a list lst, remove all elements from the dictionary whose-example-1
User Zory
by
5.8k points