defmergeLists(head1,head2):# Dummy node to simplify code head =SinglyLinkedListNode(0)# Pointer to the current node in the merged list current = headif (head1 isNone):return head2if (head2 isNone):return head1# Iterate until one of the lists is exhaustedwhile (head1 and head2):if head1.data < head2.data: current.next = head1 head1 = head1.nextelse: current.next = head2 head2 = head2.next current = current.next# Append the remaining nodes of the non-empty listif head1: current.next = head1else: current.next = head2# Return the merged list (excluding the dummy node)return head.next