小编Mar*_*iou的帖子

在Python中使用pprint.pprint之后,是否可以避免排序字典输出?

代码是:

from pprint import pprint
d = {"b" : "Maria", "c" : "Helen", "a" : "George"}
pprint(d, width = 1)
Run Code Online (Sandbox Code Playgroud)

输出为:

{'a': 'George',
'b': 'Maria',
'c': 'Helen'}
Run Code Online (Sandbox Code Playgroud)

但是,所需的输出是:

{'b': 'Maria',
'c': 'Helen',
'a': 'George'}
Run Code Online (Sandbox Code Playgroud)

可以使用pprint完成此操作,还是有其他方法?

python dictionary pretty-print pprint

5
推荐指数
1
解决办法
420
查看次数

标签 统计

dictionary ×1

pprint ×1

pretty-print ×1

python ×1