Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print a list in Python "nicely"

Tags:

python

In PHP, I can do this:

echo '<pre>' print_r($array); echo '</pre>' 

In Python, I currently just do this:

print the_list 

However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)?

like image 364
TIMEX Avatar asked Oct 06 '09 04:10

TIMEX


People also ask

How do I print a list like a string in Python?

The most pythonic way of converting a list to string is by using the join() method. The join() method is used to facilitate this exact purpose. It takes in iterables, joins them, and returns them as a string.

Can you just print a list in Python?

Use the * Operator to Print Lists in Python Except for performing multiplication, the * operator is used to print each element of a list in one line with a space between each element.


1 Answers

from pprint import pprint pprint(the_list) 
like image 168
John La Rooy Avatar answered Sep 19 '22 10:09

John La Rooy