I am confused by the linked list and nodes in python. I am currently doing a question about reversing linked list in groups of k on leetcode
class Solution:
def reverseKGroup(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
dummy = ListNode()
prev_group = dummy
while head:
j, group_end = 1, head #start of group = end after reverse
while j < k and head.next:
head = head.next
j+=1
group_start = head #end of group = start after reverse
next_group = head = head.next #start of next group