utility method def make position(selfnode)"""return position instance for given node (or none if sentinel""if node is self header or node is self trailerreturn none boundary violation elsereturn self position(selfnodelegitimate position accessors def first(self)"""return the first position in the list (or none if list is empty""return self make position(self header nextdef last(self)"""return the last position in the list (or none if list is empty""return self make position(self trailer prevdef before(selfp)"""return the position just before position (or none if is first""node self validate(preturn self make position(node prevdef after(selfp)"""return the position just after position (or none if is last""node self validate(preturn self make position(node nextdef iter (self)"""generate forward iteration of the elements of the list ""cursor self firstwhile cursor is not noneyield cursor elementcursor self after(cursorcode fragment positionallist class based on doubly linked list (continued from code fragment continues in code fragment