-1

I have two outputs which are lists:

Toprow = ['Value' , '+/-' , '%+/-' , 'High' , 'Low' , 'Prev' , 'Close']
Bottomrow = ['7,424.96', '+9.01', '+0.12', '7,447.00', '7,402.64', '7,415.95']

I want to output them so they look something like this:

FTSE 100 SUMMARY
Value         +/-       %+/-     High        Low       Prev Close
7,424.96     +9.01     +0.12   7,447.00    7,402.64     7,415.95

I believe it would be string formatting, but I'm struggling to figure out how to make it work for this.

Any help would be appreciated.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
AmsKumar
  • 93
  • 1
  • 10
  • Possible duplicate of [Printing Lists as Tabular Data](http://stackoverflow.com/questions/9535954/printing-lists-as-tabular-data) – PankajPundir Mar 17 '17 at 21:19

2 Answers2

1

You could use the following snippet:

Toprow = ['Value' , '+/-' , '%+/-' , 'High' , 'Low' , 'Prev' , 'Close']
Bottomrow = ['7,424.96', '+9.01', '+0.12', '7,447.00', '7,402.64', '7,415.95']

for item in Toprow:
    print(item, (12 - len(item)) * ' ', end='')
print()
for item in Bottomrow:
    print(item, (12 - len(item)) * ' ', end='')

This prints out each item of Toprow separately, with some spaces to format it, based on the length of the item. The same happens for Bottomrow.

Alex Boxall
  • 541
  • 5
  • 13
0

There is a string formatting way of doing this as mentioned by leovp. Alternatively, there are packages that can help with better formatting; example and the link to the package used in that example.

Community
  • 1
  • 1