Numpy-like printing for python objects
<p>While doing data analysis in Ipython I often have to look at the data by just printing its contents to the shell. Numpy have the facility to show only the <strong>margins</strong> of huge objects when they are too long themselves. I really like this feature of ndarrays but when I print internal python object (eg. dictionary with 15k objects in it) they are dumped to the screen or sometimes truncated in not very friendly fashion. 
So for example for a huge dictionary I would like to see in output something like  this  </p>

<pre><code>{ '39416' : '1397',  
  '39414' : '1397',  
  '7629'  : '7227',  
  ...,  
  '31058' : '9606',  
  '21097' : '4062',  
  '32040' : '9606' }  
</code></pre>

<p>It would be perfect if alignment and nested data structures could be taken care of. Is their a special module which can provide such functionality for python basic classes (list, dict)? Or there are some ipython configuration tricks I know nothing about?</p>

<p>There is a good built-in library <a href="https://docs.python.org/3/library/pprint.html" rel="nofollow"><code>pprint</code></a>. Take a look at it.</p>

<pre><code>&gt;&gt;&gt; from pprint import pprint
&gt;&gt;&gt; pprint({x: list(range(x)) for x in range(10)})
{0: [],
 1: [0],
 2: [0, 1],
 3: [0, 1, 2],
 4: [0, 1, 2, 3],
 5: [0, 1, 2, 3, 4],
 6: [0, 1, 2, 3, 4, 5],
 7: [0, 1, 2, 3, 4, 5, 6],
 8: [0, 1, 2, 3, 4, 5, 6, 7],
 9: [0, 1, 2, 3, 4, 5, 6, 7, 8]}
</code></pre>

python printing ipython