Python Linked List

Repository


This is a job interview task. The task is to implement a linked list using only python core functions and primitives. Also unit tests should be implemented for this linked list.

List has an init method, append method, constructor, print function. It has magic 'add' method. List consists of nodes, each node holds a value and a pointer.


I have implemented an iterator too, so the list may be iterated just as any iterable written in python.


Iteration is possible thanks to magic dunder methods, that python uses, whenever you try to iterate your class. This is what's called 'pythonic' way of doing things.


Unit tests help to have the class that is consistent with the base functionality that is required. When implementing the tests, it helps to conceptually visualize the working of the class under test.


Context manager takes the stdout that MyList class outputs after operation and checks that is what it's supposed to be. This way we that it works properly (or not).