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 
TIMAI2
2
Have a play with these two blocks....

But it will only remove the value of a key know?
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

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