title: merging two sorted linked lists python
body: <p>I have implemented a function to merge sorted linked lists but the last node isn't merging. if I set current.next to l2, I'm getting infinite loop. if I remove that it works but without the last node attached to the new list. What am I doing wrong?</p>
  
  <pre><code>def merge(self,l1,l2):
      if l1.val &lt; l2.val:
          current = l1
          l2 = l2
      else:
          current = l2
          l2 = l1
      while(current != None):
          if current.next == None and l2 != None:
              #current.next = l2 infinite loop if I include this
          elif current.next.val &gt; l2.val:
              temp = current.next
              current.next = l2
              l2 = temp
          current = current.next
  
      self.printList(current) 
  </code></pre>
  
  <p>List1: <code>5 7 16</code></p>
  
  <p>list2: <code>2 4 6 8 10</code></p>
  
  <p>Expected <code>2 4 5 6 7 8 10 16</code>, Current Result <code>2 4 5 6 7 8 10</code> </p>