title: Python, how to implement a list subclass that evaluates as False if its items evaluate False?
body: <p>I have read <a href="https://stackoverflow.com/questions/2233786/overriding-bool-for-custom-class">overriding bool() for custom class</a> and it doesn't answer my question, <strong>"how to implement a list subclass that evaluates as False if its items evaluate as False"</strong>. Specifically, it doesn't address:</p>
  
  <ul>
  <li>subclassing a list</li>
  <li>evaluating as False in a boolean context if its items evaluate as False in a boolean context</li>
  </ul>
  
  <h2>Motivation</h2>
  
  <p>One might have a data-model requires deeply nested lists of lists, and one might require an easier solution than recursing through the list of lists to determine if it has accumulated something that evaluates as True in a boolean context.</p>
  
  <h2>The Context</h2>
  
  <p>In Python an empty list evaluates as <strong><code>False</code></strong></p>
  
  <pre><code>&gt;&gt;&gt; l = list()
  &gt;&gt;&gt; l
  []
  &gt;&gt;&gt; bool(l)
  False
  </code></pre>
  
  <p>But a list with an empty list, (or some other 0 or empty container) in it evaluates as <strong><code>True</code></strong> because the len of the containing list is > 0.</p>
  
  <pre><code>&gt;&gt;&gt; l.append([])
  &gt;&gt;&gt; l
  [[]]
  &gt;&gt;&gt; bool(l)
  True
  </code></pre>
  
  <h2>Question:</h2>
  
  <p><strong>Can I subclass a list such that it is an instance of a list but that if it contains empty lists or other things that evaluate as empty or <code>False</code> will return <code>False</code>?</strong>
  i.e.:</p>
  
  <pre><code>&gt;&gt;&gt; l = MagicList((None, 0, {}, MagicList([0, False])))
  &gt;&gt;&gt; isinstance(l, list)
  True
  &gt;&gt;&gt; bool(l)
  False
  </code></pre>