如何在PyCharm控制台中打印长字典,以便每个键值对在输出中只包含一个字符串?

最佳答案

正如Kevin所建议的,使用pprint

>>> d = {a: b for a, b in zip(range(1,60), range(40, 301))}
>>> from pprint import pprint
>>> pprint(d)
{1: 40,
 2: 41,
 3: 42,
 4: 43,
 5: 44,
 6: 45,
 7: 46,
 8: 47,
 9: 48,
 10: 49,
 11: 50,
 12: 51,
 13: 52,
 14: 53,
 15: 54,
 16: 55,
 17: 56,
 18: 57,
 19: 58,
 20: 59,
 21: 60,
 22: 61,
 23: 62,
 24: 63,
 25: 64,
 26: 65,
 27: 66,
 28: 67,
 29: 68,
 30: 69,
 31: 70,
 32: 71,
 33: 72,
 34: 73,
 35: 74,
 36: 75,
 37: 76,
 38: 77,
 39: 78,
 40: 79,
 41: 80,
 42: 81,
 43: 82,
 44: 83,
 45: 84,
 46: 85,
 47: 86,
 48: 87,
 49: 88,
 50: 89,
 51: 90,
 52: 91,
 53: 92,
 54: 93,
 55: 94,
 56: 95,
 57: 96,
 58: 97,
 59: 98}

关于python - 在PyCharm控制台中打印长字典,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21273666/

10-12 06:01