Python Forum
Printing lists in a table, rows and columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing lists in a table, rows and columns
#1
I'm using python3.7.
In this first example it runs without errors.
My goal is to print the numbers in one row and the letters on the second row (or visa versa) aligned in columns. Zero over "a", one over "b", etc.
I would like help in understanding the python logic so I can achieve my goal.
numbers = [0,1,2,3,4,5,6,7,8,9]
letters = ["a","b","c","d","e","f","g","h","i","j"]

for row in range(2):
    for col in range(10):
        for num in numbers:
            print(num, end='')
        fir let in letters:
            print(let, end='')
    print()
Output:
0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij 0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij
This next example does not run, but does error.
numbers = [0,1,2,3,4,5,6,7,8,9]
letters = ["a","b","c","d","e","f","g","h","i","j"]

for row in range(2):
    for col in range(10):
        for num in numbers:
            if row==0 and col==0:
                print(num, end='')
            else:
                print(letters, end='')
    print()
Error:
tut1.py, line 16 else: ^ TabError: inconsistent use of tabs and spaces in indentation
Reply


Messages In This Thread
Printing lists in a table, rows and columns - by randy_shooflay - Sep-03-2018, 04:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a table with different sizes of columns in MS word pepe 8 1,587 Dec-08-2023, 07:31 PM
Last Post: Pedroski55
  python script for inserting rows into hbase table lravikumarvsp 7 7,119 Mar-24-2023, 04:44 AM
Last Post: parth_botadara
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,524 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,891 Dec-12-2022, 08:22 PM
Last Post: jh67
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 782 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,636 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,652 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  Dynamically Add rows to table TommyAutomagically 1 2,103 Nov-04-2021, 10:59 PM
Last Post: TommyAutomagically
  making variables in my columns and rows in python kronhamilton 2 1,630 Oct-31-2021, 10:38 AM
Last Post: snippsat
  rows from sql query need to write to a file as columns sjcsvatt 6 2,409 Oct-09-2021, 12:45 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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