-
Notifications
You must be signed in to change notification settings - Fork 0
多次元辞書を実装する
Akira Tanaka edited this page Feb 10, 2025
·
1 revision
- 辞書(dict)のkeyを2次元以上が扱えるようにする
-
qiitaの投稿にそのものがでていた(変数名hash->md_hashに変更しています)
from collections import defaultdict nested_dict = lambda: defaultdict(nested_dict) md_hash = nested_dict() # 登録 md_hash['a']['b']['c'] = 'd' md_hash['e']['f'] = 'g' # 参照 print(md_hash['a']['b']['c']) print(md_hash['e']['f'])