---
id: 688acb2053ac7978a06345f1
title: Step 21
challengeType: 20
dashedName: step-21
---

# --description--

Next, create an `elif` statement that checks that `previous_node` is not `None`. Assign `current_node.next` to `previous_node.next` inside it.

With that, if the element to be removed is found and it's not in the head node, the `next` pointer of the previous node will be updated to skip over the current node (the element to be removed), removing it from the linked list.

# --hints--

You should create an `elif` statement that checks that `previous_node` is not `None`.

```js
({ test: () => runPython(`
_cond = _Node(_code).find_class("LinkedList").find_function("remove").find_ifs()[0].find_conditions()[1]
assert _cond.is_equivalent("previous_node is not None")
`) })
```

You should assign `current_node.next` to `previous_node.next` inside the `elif` statement.

```js
({ test: () => runPython(`
_cond = _Node(_code).find_class("LinkedList").find_function("remove").find_ifs()[0]
assert _cond.is_equivalent("if current_node is None:\\n return\\nelif previous_node is not None:\\n previous_node.next = current_node.next")
`) })
```

# --seed--

## --seed-contents--

```py
class LinkedList:
    class Node:
        def __init__(self, element):
            self.element = element
            self.next = None
            
    def __init__(self):
        self.length = 0
        self.head = None

    def is_empty(self):
        return self.length == 0
    
    def add(self, element):
        node = self.Node(element)
        if self.is_empty():
            self.head = node
        else:
            current_node = self.head
            while current_node.next is not None:
                current_node = current_node.next
            current_node.next = node
        self.length += 1

    def remove(self, element):
        previous_node = None
        current_node = self.head
        while current_node is not None and current_node.element != element:
            previous_node = current_node
            current_node = current_node.next
        if current_node is None:
            return
--fcc-editable-region--
        
--fcc-editable-region--

my_list = LinkedList()
print(my_list.is_empty())

my_list.add(1)
my_list.add(2)
print(my_list.is_empty())
print(my_list.length)
```
