Is there a simple, built-in way to print a 2D Python list as a 2D matrix?
So this:
[["A", "B"], ["C", "D"]]
would become something like
A B
C D
I found the pprint module, but it doesn’t seem to do what I want.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To make things interesting, let’s try with a bigger matrix:
Output:
UPD: for multiline cells, something like this should work:
And then apply the above code.
See also http://pypi.python.org/pypi/texttable