@@ -0,0 +1,1519 @@
+#!/bin/python3%0A%0Aimport math%0Aimport os%0Aimport random%0Aimport re%0Aimport sys%0A%0Aclass SinglyLinkedListNode:%0A    def __init__(self, node_data):%0A        self.data = node_data%0A        self.next = None%0A%0Aclass SinglyLinkedList:%0A    def __init__(self):%0A        self.head = None%0A        self.tail = None%0A%0A    def insert_node(self, node_data):%0A        node = SinglyLinkedListNode(node_data)%0A%0A        if not self.head:%0A            self.head = node%0A        else:%0A            self.tail.next = node%0A%0A%0A        self.tail = node%0A%0Adef print_singly_linked_list(node, sep, fptr):%0A    while node:%0A        fptr.write(str(node.data))%0A%0A        node = node.next%0A%0A        if node:%0A            fptr.write(sep)%0A%0A# Complete the reverse function below.%0A%0A#%0A# For your reference:%0A#%0A# SinglyLinkedListNode:%0A#     int data%0A#     SinglyLinkedListNode next%0A#%0A#%0Adef reverse(head):%0A    return reverse_node(head)%0A%0Adef reverse_node(node, prev=None):%0A    if node is None:%0A        return prev%0A    next_node_to_reverse = node.next%0A    node.next = prev%0A    return reverse_node(next_node_to_reverse, node)%0A%0A%0Aif __name__ == '__main__':%0A    fptr = open(os.environ%5B'OUTPUT_PATH'%5D, 'w')%0A%0A    tests = int(input())%0A%0A    for tests_itr in range(tests):%0A        llist_count = int(input())%0A%0A        llist = SinglyLinkedList()%0A%0A        for _ in range(llist_count):%0A            llist_item = int(input())%0A            llist.insert_node(llist_item)%0A%0A        llist1 = reverse(llist.head)%0A%0A        print_singly_linked_list(llist1, ' ', fptr)%0A        fptr.write('%5Cn')%0A%0A    fptr.close()%0A

Solve reverse a linked list