# Print middle element of linked list using recursion in python

Python program for Print middle element of linked list using recursion. Here mentioned other language solution.

``````#  Python 3 program for
#  Find middle of singly linked list using recursion

def __init__(self, data) :
self.data = data
self.next = None
class SingleLL :
def __init__(self) :
self.tail = None
else :
#  Append the node at last position
self.tail.next = node
self.tail = node
def display(self) :
return
while (temp != None) :
print("",temp.data, end = " →")
#  Visit to next node
temp = temp.next
print(" NULL")
#  Find and print middle element
def printMiddle(self, node,  mid) :
if (node != None and
node.next != None and
node.next.next != None) :
#  Recursively finding the middle node
self.printMiddle(node.next.next, mid.next)
else :
#  When we get middle node
print(" Middle Node :",mid.data)
#  Handling the the request of
#  finding middle of given linked list
def findMiddle(self) :
#  When single node exist
print(" Linked list contains only one node")
else :
self.display()
def main() :
sll1 = SingleLL()
sll2 = SingleLL()
#  1 → 2 → 3 → 4 → -5 → 6 → 7 → NULL
#  4 → 9 → 7 → 3 → 8 → 6 → NULL
#  Test A
sll1.findMiddle()
#  Test B
sll2.findMiddle()

if __name__=="__main__":
main()``````

Output

`````` Linked List
1 → 2 → 3 → 4 → 5 → 6 → 7 → NULL
Middle Node : 4