본문 바로가기
Engineering WIKI/Python

[Python] One-line Tree in Python

by wonos 2021. 2. 21.
  • 파이썬 이중 딕셔너리 구조 생성
def tree(): return defaultdict(tree)

users = tree()
users['harold']['username'] = 'hrldcpr'
users['handler']['username'] = 'matthandlersux'

print(json.dumps(users))

# result
{"harold": {"username": "hrldcpr"}, "handler": {"username": "matthandlersux"}}