I’m learning Singly Linked List in university and I’m quite struggling with this data structure.

Here is my implementation:

```
from typing import Optional
class Node:
def __init__(self, data):
self.data = data
self.next: Optional[Node] = None
def __getitem__(self):
return self.data
def set_current(self, new_data):
self.data = new_data
def get_next(self):
return self.next
def set_next(self, next_data):
self.next = next_data
class SinglyLinkedList:
# Function to initialize head
def __init__(self):
self.head: Optional[Node] = None
def __len__(self):
head = self.head
count = 0
while head:
count += 1
head = head.next
return count
def __repr__(self):
head = self.head
node = []
while head:
node.append(head.data)
head = head.next
node.append("None")
return " -> ".join(map(str, node))
def __iter__(self):
node = self.head
while node:
yield node
node = node.next
def isempty(self):
return self.head == None
# def append(self, node: Optional[Node]):
def prepend(self, node: Node):
node.next = self.head
self.head = node
def append(self, node: Node):
"""
append is a function to add a new node into the tail of linked list
Time complexity: O(n)
Space complexity: O(1)
"""
head = self.head
if head is None:
head = node
self.head = head
else:
for current_node in self:
head = current_node
head.next = node
def pop_first(self):
if self.head is None:
print("The list is blank")
else:
self.head = self.head.next
def pop_last(self):
if self.head == None:
print("The list is empty")
else:
if self.head.next == None:
self.head = None
else:
head = self.head
while head.next.next is not None:
head = head.next
head.next = None
if __name__ == "__main__":
sllist = SinglyLinkedList()
sllist.prepend(Node(3))
sllist.append(Node(2))
sllist.append(Node(20))
sllist.append(Node(18))
print(f"Original list: {sllist}")
sllist.pop_last()
print(f"After pop_last: {sllist}")
```

The function `pop_last`

works fine to me but the linter seems to angry about that

Therefore, I found that my function is not clean and good as I think. How can I change `pop_last`

to be better? Thanks for your help.