def mergeTwoLists(self, l1, l2):
if not l1 and not l2:
return None
node = guard_node = ListNode(0)
while l1 and l2:
if l1.val <= l2.val:
node.next = l1
l1 = l1.next
else:
node.next = l2
l2 = l2.next
node = node.next
if l1 or l2:
node.next = l1 or l2
return guard_node.next
My Python solution using a guard node

Nice solution, here is a shorten version of your code:
def mergeTwoLists(self, l1, l2): head = dummy = ListNode(0) while l1 and l2: if l1.val < l2.val: head.next = ListNode(l1.val) # or l1 l1 = l1.next else: head.next = ListNode(l2.val) # or l2 l2 = l2.next head = head.next head.next = l1 or l2 return dummy.next

@totolipton what ListNode(0) does? I am new to programming so just want to understand if someone give me details of it.
