ㅡ. Python nested dictionary 

우리가 일반적으로 알고 있는 dictionary 는 python에서 

dictionary = { 'key1' : 'value', 'key2' : 'value' } 형태가 있습니다. 

여기에서 nested_dict = { 'dictA' : { 'nested_key1' : 'nested_value'}, 'dictB' : {'nested_key2' : 'nested_value2'} }

 

nested dictionary에 접근할 때는 다음과 같이 접근하게 됩니다.

print(dictionary['dictA']['nested_key1'])  => 'nested_value'

 

nested dictionary에 추가할 때는 다음과 같습니다.

dictionary['dictC'] = { } 생성하고 

dictionary['dictC']['nested_key3'] = 'nested_value3' 

으로 등록 하면 됩니다.

 

nested dictionary를 조회할 때는 다음과 같습니다.

for id, info in dictionary.items() : 

        print("\n id:", id) // -> dictA, dictB 

        for key in info :

          print(key+ ":" + info[key]) // -> nested_value, nested_vlaue2 

 

 

 

'Python' 카테고리의 다른 글

Python07 :: python 클래스 이름, 클래스 변수  (0) 2020.08.14
Python06 :: Python Project 구성하기  (0) 2020.08.14
Python04 :: python class  (0) 2020.08.13
Python03 :: Class  (0) 2018.12.30
Python02 :: sort  (0) 2018.12.29