title: Error "object of type 'NoneType' has no len()" on list explicitely created with list()
body: <p>I am new to Python and for my AI class I was trying to do an Huffman encoding program for strings. For that, I need to build an optimized weigthed tree. Thing is, I'm trying to call the <code>len()</code> function on a variable explicitly created with the <code>list()</code> built-in function, but it doesn't work. What am I doing wrong ?</p>
  <p>Here's the code:</p>
  <pre class="lang-py prettyprint-override"><code>def opti(text):
          occ = occurences(text)
          occ = dict(sorted(occ.items(), key=lambda item: item[1]))
          l_n = list(occ.items())
          while len(l_n) &gt; 1:
                  n1 = l_n.pop(0)
                  n2 = l_n.pop(0)
                  n = Noeud(n1[1] + n2[1], n1, n2)
                  l_n.append((n, n.valeur))
                  l_n = l_n.sort(key=lambda tup: tup[1])
          return l_n
  
  class Noeud:
          def __init__(self, value, left, right):
                  self.value = value
                  self.left = left
                  self.right = right
  </code></pre>
  <p>If I print the variable <code>l_n</code> I'm clearly getting a list so I don't understand why this isn't working. I've already tried looking for an answer on other topics but the answer mostly were about other functions modifying the type to <code>NoneType</code> whereas here I'm clearly using the list constructor function.</p>
  <p>The function <code>occurences</code> returns a dictionary containing the number of occurences of each character in a string, if that matters.</p>