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? 回答1: You can monkey patch the pprint module. import pprint pprint.pprint({"def":2,"ghi":3,"abc":1,}) pprint._sorted = lambda x:x # Or, for Python 3.7: # pprint.sorted = lambda x, key=None: x pprint.pprint({"def":2,"ghi":3, "abc":1}) Since the 2nd output is essentiallly randomly sorted, your output may be different from mine: {'abc': 1, 'def': 2, 'ghi': 3}