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>The <code>numpy</code> formatter has an ellipsis functionality; as a default it kicks in with 1000+ items.  </p>

<p><code>pprint</code> can make the display nicer, but I don't think it has an ellipsis functionality.  But you can study its docs.</p>

<p>With a list I may use a slice</p>

<pre><code>list(range(100))[:10]
</code></pre>

<p>to see a limited number of the values.</p>

<p>That's harder to do with a dictionary.  With some trial and error, this works tolerably:</p>

<pre><code>{k:dd[k] for k in list(dd.keys())[:10]}
</code></pre>

<p>(I'm on Py3 so need the extra <code>list</code>).</p>

<p>It wouldn't be hard to write your own utility functions if you can't find something in <code>pprint</code>.  It's also possible that some package on <code>pypi</code> does this.  For example a quick search turned up</p>

<p><a href="https://pypi.python.org/pypi/pprintpp" rel="nofollow">https://pypi.python.org/pypi/pprintpp</a></p>

<p><code>pprintpp</code> which claims to be actually pretty.  But like the stock <code>pprint</code> it seems to be more concerned with the nesting depth of lists and dictionaries, and not so much their length.</p>

python printing ipython