3 from collections
import defaultdict
5 def tree(key_wrapper = None):
6 return lambda :
TreeDict({}, key_wrapper)
9 return key[0].
split(
'/',1)
15 arr.SetSize(hist.GetNbinsX() + 2)
16 return np.fromiter(arr, np.float)
18 TAIL =
lambda s:
u' └── {} '.
format(s)
19 BRANCH =
lambda s:
u' ├── {} '.
format(s)
23 def __init__(self, dic = {}, key_wrapper=None):
24 super(defaultdict,self).
__init__(dic)
34 return self[key[0]][key[1]]
43 self[key[0]][key[1]] = value
47 return dict((key, val.to_dict())
if isinstance(val, TreeDict)
else (key, val)
for key, val
in self.items())
50 items =
list(self.items())
52 for i, (key, val)
in enumerate(items):
53 LS = BRANCH
if i < len(items)-1
else TAIL
54 ret +=
SPACE(
' '*len_key)*level + LS(key.ljust(len_key)) +
'\n'
55 if isinstance(val, TreeDict):
56 ret += val.__repr__(level+1)
58 ret +=
SPACE(
' '*len_key)*(level+1) + LS(
str(val).ljust(len_key)) +
'\n'
61 return p.text(
repr(self))