Skip to content
Advertisement

Disabling sorting mechanism in pprint output

I have big dictionary which I`m printing for viewing with prettyprint, but how I can keep formatting but kill sorting mechanism in pprint?

Advertisement

Answer

Python 3.8 or newer:

Use sort_dicts=False:

JavaScript

Python 3.7 or older:

You can monkey patch the pprint module.

JavaScript

Since the 2nd output is essentiallly randomly sorted, your output may be different from mine:

JavaScript

Another version that is more complex, but easier to use:
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement