I have a dictionary like:
dictionary = {
"key1" :
{
"key11" : ["a", "b"],
"key12" : "c"
},
"key2": "d",
"key3":
{
"key31" : ["e", "f"],
"key32" : "g"
}
}
and I would like to create another dictionary, with parts of first dictionary. The goal of this is to enable the user of my script to pass the keys he wants to be extracted from old file to the new file. I would like the new dictionary to be shaped for example like:
dictionary_bis = {
"key1" :
{
"key11" : ["a", "b"]
},
"key3" :
{
"key32": "g"
}
}
what I have now is something like:
dictionary_1 = {}
dictionary_1["key1"] = {}
dictionary_1["key1"]["key11"] = dictionary["key1"["key11"]
dictionary_1["key3"] = {}
dictionary_1["key3"]["key32"] = dictionary["key3"]["key32"]
which seems like a bad way, because every time the user changes keys he would like extracted, I will need to hardcode it again. There must be some more elegant way to do that.
Edit
For clarification: I have a huge document in one collection in mongodb and the users of my software want to be able to create a new document, with some data from first document and save it in another collection. This is what I came up with. It can be a copy of some elements from one dictionary to another if you please.