Python and default dict, how to pprint

后端 未结 5 1954
面向向阳花
面向向阳花 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 13:54

    If you don't have to use pprint, you can use json to pretty-print the defaultdict:

    print(json.dumps(my_default_dict, indent=4))
    

    This also works for nested defaultdicts.

提交回复
热议问题