본문 바로가기
Python/Python_basic

딕셔너리 값 추출 예제1

by Mr.DonyStark 2023. 11. 7.
#아래 딕셔너리에서 출력결과와 같이 값 추출
#Name : Kim, Age : 23, Type : office'

d = {"group1":[
                {'name':'Park', 'age':'32', 'sex':'Male'},
                {'name':'Cho', 'age':'44', 'sex':'Female'},
                {'name':'Kang', 'age':'39', 'sex':'Female', 'married':'No'}
],
"group2":[
                {'name':'Kim', 'age':'23', 'sex':'Male', 'married':'Yes'},
                {'name':'Lee', 'age':'37', 'sex':'Male', 'married':'No'}
],
"type": {'a':'employee', 'b':'office', 'c':'director', 'd':'manager', 'e':'service provider'}
    
}

ex1 = 'Name : {0}, Age : {1}, Type : {2}'.format(d['group2'][0]['name'], d['group2'][0]['age'],d['type']['b'])
ex1