I was working on a cool project I am doing in Python and I needed a way to do this without recursion because this would limit the size it could be by limiting the amount of times the loop could go through it (max recursion depth). The function needs to work on a nest dictionary of any size. How can I add entries, and retrieve, alter, or remove values from specific keys in any nested dictionary? I haven't found a good answer for this on SO because they all are either overly complex or use recursion.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
I created this simple module that demonstrates this functionality that precisely does this. You just must know the keypath, per se. You can take out the demos and use it in any project by grabbing it from Github, as this is licensed with the MIT License. Enjoy!
It'd be interesting to see this benchmarked.
Well, you could also go another way:
Which yields