mirror of
https://github.com/balkian/gists.git
synced 2024-11-24 18:32:27 +00:00
Add 'repos/2de5983237b66098945374eb79878a1d/' from commit 'f9d451457d7b731dfae3a2840dac5fc790acf237'
git-subtree-dir: repos/2de5983237b66098945374eb79878a1d git-subtree-mainline:24ac858c70
git-subtree-split:f9d451457d
This commit is contained in:
commit
36c30fec7e
20
repos/2de5983237b66098945374eb79878a1d/recursivedict.py
Normal file
20
repos/2de5983237b66098945374eb79878a1d/recursivedict.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
class RecursiveDict(UserDict):
|
||||||
|
|
||||||
|
def __getitem__(self, k):
|
||||||
|
if not isinstance(k, Iterable):
|
||||||
|
return self.data[k]
|
||||||
|
dest = self.data
|
||||||
|
for j in k:
|
||||||
|
dest = dest[j]
|
||||||
|
return dest
|
||||||
|
|
||||||
|
def __setitem__(self, k, v):
|
||||||
|
if not isinstance(k, Iterable):
|
||||||
|
return self.data[k] = v
|
||||||
|
levels = len(k)
|
||||||
|
dest = self.data
|
||||||
|
for j in range(levels-1):
|
||||||
|
if k[j] not in dest:
|
||||||
|
dest[k[j]] = {}
|
||||||
|
dest = dest[k[j]]
|
||||||
|
dest[levels-1] = v
|
Loading…
Reference in New Issue
Block a user