How do I traverse and search a python dictionary?

前端 未结 7 1083
逝去的感伤
逝去的感伤 2020-12-04 18:52

I have nested dictionaries:

{\'key0\': {\'attrs\': {\'entity\': \'p\', \'hash\': \'34nj3h43b4n3\', \'id\': \'4130\'},
          u\'key1\': {\'attrs\': {\'ent         


        
7条回答
  •  伪装坚强ぢ
    2020-12-04 19:01

    I believe pydash will give you the most efficient way to achieve this.

    For example:

    data = {'a': {'b': {'c': [0, 0, {'d': [0, {1: 2}]}]}}, 'names': {'first': 'gus', 'second': 'parvez'}}
    
    pydash.get(data, 'a.b.c.2.d.1.[1]')
    
    # output: 2
    

    Detail documentation you can find here: https://pydash.readthedocs.io/en/latest/quickstart.html

提交回复
热议问题