inputs: "Sort the biotonic doubly linked list | Node of a doubly linked list ; Function to reverse a Doubly Linked List ; swap next and prev for all nodes of doubly linked list ; Before changing head , check for the cases like empty list and list with only one node ; Function to merge two sorted doubly linked lists ; If first linked list is empty ; If second linked list is empty ; Pick the smaller value ; function to sort a biotonic doubly linked list ; if list is empty or if it contains a single node only ; if true , then ' current ' is the first node which is smaller than its previous node ; move to the next node ; if true , then list is already sorted ; spilt into two lists , one starting with ' head ' and other starting with ' current ' ; reverse the list starting with ' current ' ; merge the two lists and return the final merged doubly linked list ; Function to insert a node at the beginning of the Doubly Linked List ; allocate node ; put in the data ; since we are adding at the beginning , prev is always None ; link the old list off the new node ; change prev of head node to new node ; move the head to point to the new node ; Function to print nodes in a given doubly linked list ; if list is empty ; Driver Code ; Create the doubly linked list : 2 < .5 < .7 < .12 < .10 < .6 < .4 < .1 ; sort the biotonic DLL"
How can the above be solved in Python?
targets: class Node :
	def __init__ ( self , next = None , prev = None , data = None ) :
		self . next = next
		self . prev = prev
		self . data = data
def reverse ( head_ref ) :
	temp = None
	current = head_ref
	while ( current != None ) :
		temp = current . prev
		current . prev = current . next
		current . next = temp
		current = current . prev
	if ( temp != None ) :
		head_ref = temp . prev
		return head_ref
def merge ( first , second ) :
	if ( first == None ) :
		return second
	if ( second == None ) :
		return first
	if ( first . data < second . data ) :
		first . next = merge ( first . next , second )
		first . next . prev = first
		first . prev = None
		return first
	else :
		second . next = merge ( first , second . next )
		second . next . prev = second
		second . prev = None
		return second
def sort ( head ) :
	if ( head == None or head . next == None ) :
		return head
	current = head . next
	while ( current != None ) :
		if ( current . data < current . prev . data ) :
			break
		current = current . next
	if ( current == None ) :
		return head
	current . prev . next = None
	current . prev = None
	current = reverse ( current )
	return merge ( head , current )
def push ( head_ref , new_data ) :
	new_node = Node ( )
	new_node . data = new_data
	new_node . prev = None
	new_node . next = ( head_ref )
	if ( ( head_ref ) != None ) :
		( head_ref ) . prev = new_node
	( head_ref ) = new_node
	return head_ref
def printList ( head ) :
	if ( head == None ) :
		print ( " Doubly ▁ Linked ▁ list ▁ empty " )
	while ( head != None ) :
		print ( head . data , end = " ▁ " )
		head = head . next
head = None
head = push ( head , 1 )
head = push ( head , 4 )
head = push ( head , 6 )
head = push ( head , 10 )
head = push ( head , 12 )
head = push ( head , 7 )
head = push ( head , 5 )
head = push ( head , 2 )
print ( " Original ▁ Doubly ▁ linked ▁ list : n " )
printList ( head )
head = sort ( head )
print ( " Doubly linked list after sorting : " )
printList ( head )