A Python implementation of a singly linked list with basic operations and Pythonic interfaces.
- Insert at beginning (
insert_at_beginning) - Append at end (
append) - Insert at any index (
insert_at) - Remove from beginning (
remove_at_beginning) - Remove from end (
remove_at_end) - Delete at any index (
delete_at) - Iterable support (
__iter__) - Length support (
__len__) - Clean string representation (
__repr__)
Clone the repository:
git clone <repo-url>
cd linked_listfrom linked_list import LinkedList
ll = LinkedList()
ll.insert_at_beginning(10)
ll.append(20)
ll.insert_at(15, 1)
print(ll) # 10->15->20
ll.remove_at_beginning()
ll.remove_at_end()
ll.delete_at(0)All methods are tested using Python's unittest:
python -m unittest test_linked_list.py- Python automatically manages memory; no manual deletion needed.
- Deleting from an empty list is safe (no exception).
- Out-of-bounds indices raise an
Exception.