Stop Using print() Every Time In Python — Use pprint() Instead
<h1>Enter our benevolent saviour pprint()</h1>
<p><code>pprint</code> is built-in, so we don’t need to install anything.</p>
<pre>
from pprint import pprint
pprint(x)</pre>
<ul>
<li>one simple <code>from pprint import pprint</code> line is needed</li>
<li>it makes our messy data more human-readable</li>
<li>it doesn’t require us to manually make it human-readable</li>
</ul>
<h1>Can’t we just write a for loop instead?</h1>
<p>Let’s say we have a even more messy data structure.</p>
<pre>
x = {
'name':'tom',
'dad': {'name': 'jerry',
'dad':{'name':'greg'},
'mom':{'name':'susie'}
},
'mom': {'name': 'mary'},
'wife': {'name': 'susan'},
'son': {'name': 'tim',
'dad':{'name':'tom'},
'mom':{'name':'susan'},
'wife':{'name':'cassie'},
'daughter': {'name':'lala',
'husband': 'bobo'
}
}
}</pre>
<p>Here we have some screwed up family tree as an example with multiple multiple levels of nesting.</p>
<p>We have 2 options to visualize this:</p>
<ol>
<li>we manually write a recursive function to print out everything</li>
<li>we use <code>pprint</code></li>
</ol>
<p><a href="https://levelup.gitconnected.com/stop-using-print-every-time-in-python-use-pprint-instead-e8761b25048f"><strong>Read More</strong></a></p>