How do I traverse and search a python dictionary?

前端 未结 7 1077
逝去的感伤
逝去的感伤 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:17

    Well, if you have to do it only a few times, you can just use nested dict.iteritems() to find what you are looking for.

    If you plan to do it several times, performances will quickly becomes an issue. In that case you could :

    • change the way you data is returned to you to something more suitable.

    • if you can't, convert the data once the fly to a dict between id and keys (using iteritems). Then use it.

提交回复
热议问题