title: How to create a recursive function to delete node from linked list with given key in python?
body: <p>I tried program to delete node from linked list recursively. My program is given below</p>
  <pre><code>class node:
      def __init__(self, data=None):
          self.data = data
          self.next = None
  
  class linkedList:
      def __init__(self):
          self.head=None
  
      def printList(self):
          cur = self.head
          while(cur != None):
              print(cur.data,end=&quot;-&gt;&quot;)
              cur=cur.next
          print(&quot;null&quot;)
  
      def push(self,dat):
          newNode = node(dat)
  
          temp = self.head
          self.head = newNode
  
          newNode.next = temp
  
      @staticmethod
      def dnr(head, key):
          if head is not None:
              if head.data == key:
                  head=head.next
                  return head
          if head is not None:
              head.next = linkedList.dnr(head.next, key)
              return head
          return head
  
  
      
  
  if __name__ == '__main__':
      ll=linkedList()
  
      ll.push(3)
      ll.push(6)
      ll.push(9)
      ll.push(12)
      ll.push(15)
  
      ll.printList()
      print(&quot;*******&quot;)
  
      # ll.head = linkedList.dnr(ll.head,2)
      linkedList.dnr(ll.head,9)
      ll.printList()
  </code></pre>
  <p>The problem with this is that this does not work for first element.To make it work for first element I have to call the function like this
  <code> ll.head = linkedList.dnr(ll.head,2)</code></p>
  <p>second thing is that I wanted my function to call this way
  <code> ll.dnr(2)</code></p>
  <p>please tell me how to create a recursive function to delete node in linked list in python</p>