ComputerScienceStudent ComputerScienceStudent - 1 year ago 88
Python Question

Printing list as table (row, col)

I'm trying to print a list as a table

The following code creates specified amount of rows and columns (in other words, it creates a list of a specified size).

finalgrid1 =[[0 for j in range(keyword_size)] #print rows (size of keyword)
for i in range(1 + new_grid_size)] #print column (size of ciphers)

The result printed is (when keyword_size = 3):

[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]

Could someone show me how to print it in the following format.

[[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]

I'm working on creating a Cipher encoder and decoder program as part of an assignment.
I've implemented the majority of it already - just stuck with printing it in the right format (as a table).
Btw, I am not asking you to apply any changes whatsoever, I only want to know how to print the list in the format of a table, that's all.

I appreciate your help

Answer Source

Try this, essentially prints each list out until there are none left to print

i = 0
while i < len(finalgrid1):
    print finalgrid1[i]
    i += 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download