title: Inserting Node at a specific location python
body: <p>This question is a hackerrank challenge. link here: <a href="https://www.hackerrank.com/challenges/insert-a-node-at-a-specific-position-in-a-linked-list" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/insert-a-node-at-a-specific-position-in-a-linked-list</a></p>
  
  <pre><code>"""
  Insert Node at a specific position in a linked list
  head input could be None as well for empty list
  Node is defined as
  
   class Node(object):
  
     def __init__(self, data=None, next_node=None):
         self.data = data
         self.next = next_node
  
   return back the head of the linked list in the below method. 
  """
  #This is a "method-only" submission.
  #You only need to complete this method.
  def InsertNth(head, data, position):
      node = head 
      if position == 0: 
          node = Node(data)
          node.data = data 
          node.next = head 
          return node
      else: 
          while position &gt; 0: 
              node = node.next 
  
              i = node.next
              node.next = Node(data)
              node.next.next = i 
              return head
  </code></pre>
  
  <p>my current output is 321024, but I need it to be 310542. Any help is greatly appreciated! </p>