Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting lists
#6
It's because you're passing in two different data types, int and str, and the default for format is to left-justify strings, but right-justify numbers. So they end up on the opposite side.

There's no right way to do this. Shrinking the size as small as possible helps. Changing the ints to strs works okay, but you lose the numeric alignment. For small numbers this is okay, but if you have a mix of sizes, it's very confusing.

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(*(str(x) for x in row)))
Output:
1 2 3 4 5 d h f s g
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,362 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,256 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