Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print array as a table in python

Tags:

python

I'm trying to print an array like: Table = [(0,0,0),(0,0,1),(0,1,0)].

Therefore, I want to print this array as a table like:

0 0 0
0 0 1
0 1 0

How can I make this?

I tried a simple print Table but this prints the array like this:

[(0,0,0),(0,0,1),(0,1,0)]
like image 440
PRVS Avatar asked Mar 19 '26 16:03

PRVS


1 Answers

Have you tried a basic for loop?

for line in Table:
    print ' '.join(map(str, line))

It's prettier in Python 3:

for line in Table:
    print(*line)
like image 137
TigerhawkT3 Avatar answered Mar 22 '26 05:03

TigerhawkT3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!