#### Reverse K Group

A
I
```from __future__ import annotations

from collections.abc import Iterable, Iterator
from dataclasses import dataclass

@dataclass
class Node:
data: int
next_node: Node | None = None

def __init__(self, ints: Iterable[int]) -> None:
self.head: Node | None = None
for i in ints:
self.append(i)

def __iter__(self) -> Iterator[int]:
"""
>>> ints = []
True
>>> ints = tuple(range(5))
True
"""
while node:
yield node.data
node = node.next_node

def __len__(self) -> int:
"""
>>> for i in range(3):
True
True
True
8
"""
return sum(1 for _ in self)

def __str__(self) -> str:
"""
''
'0 -> 1 -> 2 -> 3 -> 4'
"""
return " -> ".join([str(node) for node in self])

def append(self, data: int) -> None:
"""
>>> tuple(ll)
(1, 2)
>>> ll.append(3)
>>> tuple(ll)
(1, 2, 3)
>>> ll.append(4)
>>> tuple(ll)
(1, 2, 3, 4)
>>> len(ll)
4
"""
return
while node.next_node:
node = node.next_node
node.next_node = Node(data)

def reverse_k_nodes(self, group_size: int) -> None:
"""
reverse nodes within groups of size k
>>> ll = LinkedList([1, 2, 3, 4, 5])
>>> ll.reverse_k_nodes(2)
>>> tuple(ll)
(2, 1, 4, 3, 5)
>>> str(ll)
'2 -> 1 -> 4 -> 3 -> 5'
"""
return

length = len(self)

while length >= group_size:
current_node = previous_node.next_node
assert current_node
next_node = current_node.next_node
for _ in range(1, group_size):
assert next_node, current_node
current_node.next_node = next_node.next_node
assert previous_node
next_node.next_node = previous_node.next_node
previous_node.next_node = next_node
next_node = current_node.next_node
previous_node = current_node
length -= group_size