Python and default dict, how to pprint

后端 未结 5 1955
面向向阳花
面向向阳花 2020-12-28 13:37

I am using default dict. I need to pprint.

However, when I pprint ...this is how it looks.

defaultdict(

        
5条回答
  •  自闭症患者
    2020-12-28 14:02

    I really like this solution for dealing with nested defaultdicts. It's a bit of a hack, but does the job neatly when pdbing:

    import json
    data_as_dict = json.loads(json.dumps(data_as_defaultdict))
    print(data_as_dict)
    

    From: https://stackoverflow.com/a/32303615/4526633

提交回复
热议问题