Clearing a list
We may want a quick way to clear a list. Fortunately for us, this is very simple. All we do is clear the pointers head
and tail
by setting them to None
:
def clear(self): """ Clear the entire list. """ self.tail = None self.head = None
In one fell swoop, we orphan all the nodes at the tail
and head
pointers of the list. This has a ripple effect of orphaning all the nodes in between.