linked-list: Implemented new exercise by behrtam · Pull Request #212 · exercism/python
I'll take a deeper look at it tonight, but these were my notes looking at the problem.
Notes regarding problem as a whole
- The ReadMe does not prohibit structures implemented by the standard library
- I wish the exercise didn't use the abbreviated name of double ended queue. It could be confused with dequeue later on. Dequeue is commonly used to refer to removing an element from a FIFO queue.
- I wish that the ReadMe mentioned sentinel nodes for extra reading.
Notes regarding your implementation
- It looks like your code can't handle a call attempting to remove an element from an empty queue. It would also be nice to test this case.
- It'd be ideal not to use the variable name next, only because of overwriting the built in function. A better name isn't immediately coming to mind. Its very minor though. Its really if we can come up with a synonym, it'd be preferable.
Extra Credit Ideas
What I think would be very cool to do for this problem is to have users implement a couple magic methods like __iter__ in python. I'm not sure how to add the extra language specific information for it, but this means they could then iterate their structure just like a list.
for x in my_deque: do_something(x)
It would also work with built ins:
iterator = iter(my_deque) first = next(iterator) second = next(iterator)
It could also be interesting to make them implement __len__, and keep track of the size of their structure.
my_deque = Deque() my_deque.push(1) my_deque.push(2) size = len(my_deque) assert size == 2
Some other magic methods to consider are __getitem__, __setitem__, and __reversed__