Find a given key's value in a nested ordered dict python

前端 未结 3 1989
有刺的猬
有刺的猬 2021-01-24 08:31

I am trying to find the value of a given key from a nested OrderedDict.

Key points:

  • I don\'t know how deep this dict will be nested
  • The name of t
3条回答
  •  星月不相逢
    2021-01-24 09:22

    Try this

    mydict = ['KYS_Q1AA_YouthSportsTrustSportParents_P',
            ['KYS_Q1AA',
               [{'chart_layout': '3'},
                {'client_name': 'Sport Parents (Regrouped)'},
                 {'sort_order': 'asending'},
                 {'chart_type': 'pie'},
                 {'powerpoint_color': 'blue'},
                 {'crossbreak':'Total'}
                 ]]]
    

    Then...

    print mydict[1][1][4]['powerpoint_color']
    

提交回复
热议问题