Skip to content
Advertisement

Pretty print 2D list?

Is there a simple, built-in way to print a 2D Python list as a 2D matrix?

So this:

JavaScript

would become something like

JavaScript

I found the pprint module, but it doesn’t seem to do what I want.

Advertisement

Answer

To make things interesting, let’s try with a bigger matrix:

JavaScript

Output:

JavaScript

UPD: for multiline cells, something like this should work:

JavaScript

And then apply the above code.

See also http://pypi.python.org/pypi/texttable

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement