More linked lists

We worked more on our linked list implementation. See the lecture capture for details.

class ListNode:
    def __init__(self, data): = data = None

class LinkedList:
    def __init__(self):
        self.first = None

    def append_to(self, node: ListNode, data):
        if not
   = ListNode(data)
            self.append_to(, data)

    def append(self, data):
        if not self.first:
            self.first = ListNode(data)
            self.append_to(self.first, data)

    def length_from(self, node):
        if not
            return 1
        return 1 + self.length_from(

    def length(self):
        if not self.first:
            return 0
        return self.length_from(self.first)

    def nth_from(self, node, n):
        if n == 0:
        return self.nth_from(, n - 1)

    def nth(self, n):
        if self.length() <= n:
            raise Exception("index out of range")
        return self.nth_from(self.first, n)