개발 모음집/Python

[Python] One-line Tree in Python

wonos 2021. 2. 21. 19:29
  • 파이썬 이중 딕셔너리 구조 생성
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"}}