python - 用“:”分隔的键值对格式化字符串

python - formatting a string with key value pair separate by ':'

我正在构建以下模式的字符串

"Key1":"Value1"
"Key1232131":"Value2"
"Key12321":"Value3"

我想格式化成

"Key1"          :   "Value1"
"Key1232131"    :   "Value2"
"Key12321"      :   "Value3"

我试图将它们插入字典并漂亮地打印出来,但没有成功。我想我可能需要 table 之类的代表。我可以在 python/in general 中使用什么来实现这一点?

创建矩阵是一种解决方案:

matrix = [['Key1 :', 'Value1'], ['Key1232131 :', 'Value2'], ['Key12321 :', 'Value3']]
for row in matrix:
   print ' '.join(row)

How to make matrices in Python? 显示如何制作一般的矩阵

>>> key="Key1" 
>>> value = "Value1"
>>> '{!r:<10}:{!r:>10}'.format(key, value)
"'Key1'    :  'Value1'"