title: AttributeError: 'NoneType' object has no attribute '...'
body: <p>I was working with doubly linked lists in Python when I encountered with this error:</p>
  <pre><code>    def merge(self,other):
          mergedCenter = HealthCenter()
          selfPatient = self._head
          otherPatient = other._head
          print(selfPatient.elem)
          print(selfPatient.elem &lt; otherPatient.elem)
          while (selfPatient or otherPatient):
              if selfPatient.elem &lt; otherPatient.elem:
                  mergedCenter.addLast(selfPatient.elem)
                  selfPatient = selfPatient.next
              elif selfPatient.elem &gt; otherPatient.elem:
                  mergedCenter.addLast(otherPatient.elem)
                  otherPatient = otherPatient.next
              else:
                  mergedCenter.addLast(selfPatient.elem)
                  selfPatient = selfPatient.next
                  otherPatient = otherPatient.next
          return (mergedCenter)
  </code></pre>
  <p>I get this output:</p>
  <pre><code>Abad, Ana   1949    True    0
  True
  Traceback (most recent call last):
    File &quot;main.py&quot;, line 189, in &lt;module&gt;
      hc3 = hc1.merge(hc2)
    File &quot;main.py&quot;, line 112, in merge
      if selfPatient.elem &lt; otherPatient.elem:
  AttributeError: 'NoneType' object has no attribute 'elem'
  </code></pre>
  <p>There's already a method implemented to compare .elem as you can clearly see in the second print, but I don't understand why in the first conditional it keeps breaking.</p>
  <p>Thanks in advance.</p>
  <p>Solution:
  <strong>Had to take into account the length of both DLists, not to get one of both values 'Nonetype'. This is solved changing the OR for AND, and checking later which one is not 'Nonetype' to finish merging</strong></p>