Let a class behave like it's a list in Python
<p>I have a class which is essentially a collection/list of things. But I want to add some extra functions to this list. What I would like, is the following: </p>

<ul>
<li>I have an instance <code>li = MyFancyList()</code>. Variable <code>li</code> should behave as it was a list whenever I use it as a list: <code>[e for e in li]</code>, <code>li.expand(...)</code>, <code>for e in li</code>. </li>
<li>Plus it should have some special functions like <code>li.fancyPrint()</code>, <code>li.getAMetric()</code>, <code>li.getName()</code>.</li>
</ul>

<p>I currently use the following approach:</p>

<pre><code>class MyFancyList:
  def __iter__(self): 
    return self.li 
  def fancyFunc(self):
    # do something fancy
</code></pre>

<p>This is ok for usage as iterator like <code>[e for e in li]</code>, but I do not have the full list behavior like <code>li.expand(...)</code>.</p>

<p>A first guess is to inherit <code>list</code> into <code>MyFancyList</code>. But is that the recommended pythonic way to do? If yes, what is to consider? If no, what would be a better approach?</p>