0

I am building a string of following pattern

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

I want to format it like

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

I tried to insert them in a dictionary and pretty print it but that doesn't do it. I think I might need a table like representation. What can I use in python/in general to achieve this?

nick01
  • 333
  • 1
  • 8
  • 19
  • Hi - can you show us the code you've tried (even if it isn't working)? (edit your question and add it there, don't reply in comments because code formatting here is awful) – Taryn East Feb 10 '15 at 23:09

2 Answers2

6
>>> key="Key1" 
>>> value = "Value1"
>>> '{!r:<10}:{!r:>10}'.format(key, value)
"'Key1'    :  'Value1'"
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
0

Creating a matrix is one solution:

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

How to make matrices in Python? shows how to make a matrix in general

Community
  • 1
  • 1
Jonathan Epstein
  • 369
  • 2
  • 12