linkedlist.py
def insert(self, new_element, position):
        """Insert a new node at the given position.
        Assume the first position is "1".
        Inserting at position 3 means between
        the 2nd and 3rd elements."""
        prev = self.head
        i = 1
        while (prev.next) and (i < position-1):
            prev = prev.next
            i += 1
        if (i == position - 1):
            if prev.next:
                new_element.next = prev.next
            prev.next = new_element
        if (position == 1):
            self.head = new_element
            if prev:
                new_element.next = prev
Insert a new node at the given position.
        Assume the first position is "1".
        Inserting at position 3 means between
        the 2nd and 3rd elements.
Insert a new node at the given position.
Assume the first position is "1".
Inserting at position 3 means between
the 2nd and 3rd elements.
Insert a new node at the given position . Assume the first position is " 1 " . Inserting at position 3 means between the 2nd and 3rd elements .
def insert(self, new_element, position):
        prev = self.head
        i = 1
        while (prev.next) and (i < position-1):
            prev = prev.next
            i += 1
        if (i == position - 1):
            if prev.next:
                new_element.next = prev.next
            prev.next = new_element
        if (position == 1):
            self.head = new_element
            if prev:
                new_element.next = prev
def insert ( self , new_element , position ) : prev = self . head i = 1 while ( prev . next ) and ( i < position - 1 ) : prev = prev . next i += 1 if ( i == position - 1 ) : if prev . next : new_element . next = prev . next prev . next = new_element if ( position == 1 ) : self . head = new_element if prev : new_element . next = prev
Insert a new node at the given position.
Insert a new node at the given position .
"""Insert a new node at the given position.
        Assume the first position is "1".
        Inserting at position 3 means between
        the 2nd and 3rd elements."""
self
new_element
position