0

Please, I need help. How can I do this? Aligned columns and rows, and adjust to the left.

May be, these are the variables:

a1=5548867423267
b1=4
c1=11346778
d1=344
e1=67
f1=9745
g1=9745
h1=9745
a2=55467423267
b2=7
c2=1134476778
d2=344447774
e2=647
f2=9744775
g2=97474545
h2=974776545
a3=5548867423267
b3=4
c3=11346778
d3=344
e3=67
f3=9745
g3=9745
h3=9745
a4=5548867423267
b4=4
c4=11346778
d4=344
e4=67
f4=9745
g4=9745
h4=9745

These are the lists that contain text and variables:

L1 = [" ","A","B","C","D","E","F","G","H"]
L2 = ["CLASS1",a1,b1,c1,d1,e1,f1,g1,h1]
L3 = ["CLASS2",a2,b2,c2,d2,e2,f2,g2,h2]
L4 = ["CLASS3",a3,b3,c3,d3,e3,f3,g3,h3]
L5 = ["CLASS4",a4,b4,c4,d4,e4,f4,g4,h4]

I want the result something like this:

         A               B          C              D   E  F    G    H
CLASS1   5548867423267   4          11346778       344 67 9745 9745 974
CLASS2   .......         .          ........       ... .. 9745 9745 974
CLASS3   .............   .          ........       ... .. 9745 9745 974
CLASS4   ....            .          ........       ... .. 9745 9745 974
Abdalla
  • 13
  • 1
  • I'm sorry. I'm not familiar with coding. – Abdalla Jan 22 '17 at 07:54
  • Refer the linked question in order to format the content in tabular format. Also, you should not be storing these values as variable, and then creating the list using the those variable. You should have created your list using the actual values (skipping intermediate variables) – Moinuddin Quadri Jan 22 '17 at 07:57
  • I don't mean variables exactly. What I mean that the numbers are called from above. Text and numbers not text only. – Abdalla Jan 22 '17 at 08:00
  • @Abdalla, use `str.format` function – RomanPerekhrest Jan 22 '17 at 08:03

1 Answers1

0

The solution using str.format() function:

for cl, a,b,c,d,e,f,g,h in [L1,L2,L3,L4,L5]:
    print('{:<10} {:<15} {:<10} {:<15} {:<10} {:<10} {:<10} {:<10} {:<10}'.format(cl,a,b,c,d,e,f,g,h))

The output:

           A               B          C               D          E          F          G          H         
CLASS1     5548867423267   4          11346778        344        67         9745       9745       9745      
CLASS2     55467423267     7          1134476778      344447774  647        9744775    97474545   974776545 
CLASS3     5548867423267   4          11346778        344        67         9745       9745       9745      
CLASS4     5548867423267   4          11346778        344        67         9745       9745       9745     
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105