Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting lists
#5
(Nov-24-2020, 11:38 PM)bowlofred Wrote: Use a formatting package. As an example, you could look at tabulate, but there are several others.

Otherwise, you need to calculate the size of your fields yourself and enforce that size with formatting commands.


table = [["A", "B", "C"],
         ["D", "Epsilon", "Foxtrot city"],
         ["South Mangrove", "T", "U"]]

Thanks for that. I just get some thing a bit different


list_a=[[1,2,3,4,5],
        ['d','h','f','s','g']]



 #a=0, a=1,a=2, a=3, a=4,a=5
for row in list_a:
    print("{:15} {:15} {:15} {:15}{:15} ".format(*row))]])

[output]
              1               2               3               4              5 
d               h               f               s              g               

any idea why 1 and d are not in line and the rest?

Thanks.
[output]--------------  -------  ------------
A               B        C
D               Epsilon  Foxtrot city
South Mangrove  T        U
--------------  -------  ------------[/output]

Manual example:
[python]table = [["A", "B", "C"],
         ["D", "Epsilon", "Foxtrot city"],
         ["South Mangrove", "T", "U"]]

for row in table:
    print("{:15} {:15} {:15}".format(*row))
Output:
A B C D Epsilon Foxtrot city South Mangrove T U
Reply


Messages In This Thread
Formatting lists - by rturus - Nov-24-2020, 10:57 PM
RE: Formatting lists - by bowlofred - Nov-24-2020, 11:38 PM
RE: Formatting lists - by rturus - Nov-26-2020, 01:18 PM
RE: Formatting lists - by Axel_Erfurt - Nov-25-2020, 08:23 AM
RE: Formatting lists - by snippsat - Nov-25-2020, 01:12 PM
RE: Formatting lists - by bowlofred - Nov-26-2020, 04:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,404 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,306 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020