How to print a list in Python "nicely"
from pprint import pprint
pprint(the_list)
Simply by "unpacking" the list in the print function argument and using a newline (\n) as separator.
print(*lst, sep='\n')
lst = ['foo', 'bar', 'spam', 'egg']
print(*lst, sep='\n')
foo
bar
spam
egg
A quick hack while debugging that works without having to import pprint
would be to join the list on '\n'
.
>>> lst = ['foo', 'bar', 'spam', 'egg']
>>> print '\n'.join(lst)
foo
bar
spam
egg