开发者

Creating a dictionary from another dictionary keeping the structure intact

开发者 https://www.devze.com 2023-03-05 17:55 出处:网络
I have a big dictionary with deep hierarchy in it... I want to read it and create another dictionary with same structure but with some modifications while I am reading the source dictionary.

I have a big dictionary with deep hierarchy in it... I want to read it and create another dictionary with same structure but with some modifications while I am reading the source dictionary.

Modifications are like if the keyName is "server" then remove that key, if the keyName is "notification" then alter its value.

What is the best way to开发者_开发问答 do this keeping the structure of source dictionary intact.


Read the Deep Copies section of Collections Programming Topics. In fact, you should really read the entire document. You'll end up reading it all at some point anyway (or worse, having us repeatedly point you there), and it's only a few dozen pages.

I know this probably isn't the answer you were looking for, but the alternative is for someone here to code up a method that deep copies dictionaries for you. I'm not going to do that. If you get stuck on something specific, by all means, ask here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号