我想使用PrettyPrinter将python字典打印到一个文件中(为了便于阅读),但为了进一步提高可读性,我在输出文件中按键对字典进行了排序。所以:
mydict = {'a':1, 'b':2, 'c':3}
pprint(mydict)
当前打印到
{'b':2,
'c':3,
'a':1}
我想把字典打印出来,但要按关键字PrettyPrint。
{'a':1,
'b':2,
'c':3}
做这件事最好的方法是什么?
https://stackoverflow.com/questions/1479649
复制相似问题