I’m trying to print a simple table in python, but none of the previous answers seem to be exactly what I’m looking for. Any and all help would be greatly appreciated.
I have a list (of texts):
texts = [caesar,hamlet,macbeth,emma,persuasion,sense]
I then run a function called ‘similarity,’ which compares 2 texts. I’d like to print the results in a table, but I can’t seem to get a new line after the print statement has iterated through one loop of the list. [Note: I’m using Python 2.6.6, because I’m using Natural Language Toolkit, a python module for linguistics.]
Here is my current print statement, which does not work correctly:
for x in texts:
for y in texts:
print round(similarity(x,y),2),
if texts.index(x) == len(texts):
print '\n'
Any pointers in the right direction would be great!
Just use
printon a line of its own.Also, why aren’t you doing something like this?