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)?
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.
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.
from pprint import pprint pprint(the_list)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With