For convenience, I'd like to use a linked list Node
class like the following:
a = Node(3)
b = Node(2, a)
c = Node(1, b) # c = (1) -> (2) -> (3)
I've tried the following class definition
class Node:
def __init__(self, val: int, next_node: Node = None):
self.val = val
self.next = next_node
... but I'm getting a NameError
about Node
in the constructor.
I recognize that this is recursive, but nevertheless I've seen this done in other languages. Is this possible in Python?