class Node:
    def __init__(self, item):
        self.item = item
        self.next = None

# seznam 1, 2, 3
list = Node(1)
list.next = Node(2)
list.next.next = Node(3)

# totéž
node_1 = Node(1)
node_2 = Node(2)
node_3 = Node(3)

node_1.next = node_2
node_2.next = node_3
# node_1.next.next = node_3

def print_list(node):
    while node is not None:
        print(node.item, end="\n" if node.next is None else ", ")

        # node.next is None ? "\n" : ", "
        # if node.next is None:
        #     print(node.item, end="\n")
        # else:
        #     print(node.item, end=", ")

        node = node.next

print_list(list)
print_list(node_1)

# změnit hodnotu prvního prvku list na 11
list.item = 11

print_list(list)

# změnit hodnotu druhého prvku na 22
list.next.item = 22

# změnit hodnotu třetího prvku na 33
list.next.next.item = 33

print_list(list)

# vymazat první prvek

list = list.next
print_list(list)

# přidat na začátek prvek s hodnotou 1
node_1 = Node(1)
node_1.next = list
print_list(node_1)
print_list(list)
list = node_1

# přidat na druhé místo prvek s hodnotou 2
node_2 = Node(2)
node_2.next = list.next
list.next = node_2
print_list(list)

# přidat prvek 4 na konec spojového seznamu
last = list
while last.next is not None:
    # print(last.item)
    last = last.next

# last = list
# while True:
#     if last.next is None:
#         break
#     last = last.next

last.next = Node(4)

print_list(list)

# vymazat poslední prvek spojového seznamu

next_to_last = list
while True:
    if next_to_last.next.next is None:
        break
    next_to_last = next_to_last.next

next_to_last.next = None
print_list(list)
