python - 在 PyCharm 控制台中打印长字典

标签 python dictionary printing pycharm

如何在 PyCharm 控制台中打印一本长字典,以便每个键值对在输出中仅采用一个字符串?

最佳答案

正如凯文建议的那样,使用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/

相关文章:

python - 按时间值对结果列表进行切片

python - 如何忽略 AttributeError : 'NoneType'

python - 根据范围获取子词典

javascript - 在 JS、JQ 或 Angular 中打印远程页面

python - 图像opencv python特定区域的形状检测

Python pandas 获取数据帧的最大连续次数

python - 如何在 Python 的 json 文件中将键与嵌套级别连接起来?

swift - 无法转换类型 [(key :string, value :int)] to specified type Dictionary<String, Int>

css - translate3d 内部溢出 :hidden leaks to second page when printed

python - 同时打印 x 次 - Python