1

I'm trying to print a formatted horizontal list after a prompt. This is what I've tried:

def displayList(prompt, list_):
    print(f"{prompt:>20}:",*list_, sep = f"{'':>4}")

but when displaying multiple lists on top of each other I get this:

              List 1:    6    2    4    8    4
              List 2:    6    3    5    9    1
          Added List:    12    5    9    17    5
     Multpilied List:    36    6    20    72    4

but I want this:

              List 1:     5    4    8    6    4  

              List 2:     4    9   10    1    2  

          Added List:     9   13   18    7    6  

     Multpilied List:    20   36   80    6    8 
Oozaru42
  • 21
  • 4

1 Answers1

2

You need to apply a field width to each list item rather than a fixed-width separator. For example:

print(f'{prompt:>20}:' + ', '.join(f'{e:>10}' for e in list_))
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264