How do I delete a list of keys from a dictionary?

Hello all, I have a doubt about how to delete a list of keys from a dictionary.
An example:

List ["1", "2", "5", "7", "9"]
Dictionary {"1" : "Value1", "2" : "Value2", "3" : "Value3", "4" : "Value4", "5" : "Value5", "6" : "Value6", "7" : "Value7", "8" : "Value8", "9" : "Value9"}

OK, now I have a list of numbers and a dictionary, So how can I delete all the keys specified in the list from the dictionary?

The Output Dictionary will be:
{"3" : "Value3", "4" : "Value4", "6" : "Value6", "8" : "Value8"}
All the list number keys has been removed

Thank you for your kindness :smiling_face_with_three_hearts:

Have a play with these two blocks....

image

But it will only remove the value of a key know?

1 Like

I had a long plan to remove one item from a dictionary

initialize dictionary = {"1" : "Value1", "2" : "Value2", "3" : "Value3", "4" : "Value4", "5" : "Value5", "6" : "Value6", "7" : "Value7", "8" : "Value8", "9" : "Value9"};
initialize itemToDelete = "4";

initialize local variable "newDictionary" to `create new dictionary`;
  in {
        for each key with dictionary in dictionary `dictionary` {
          if (key != itemToDelete) {
            merge into dictionary `newDictionary`
                  from `make a dictionary {key : value}`
          }
       }

Oh Thank you, I didn't notice this post. And it worked, thank you very much :smiling_face_with_three_hearts: :star_struck:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.