<jupyter_start><jupyter_text>Reverse a Linked List[The Original Question](https://mp.weixin.qq.com/s/lvEC4JlPSGUDw9t7I3jSdg)  QuestionGiven a singly-linked list, reverse the list. This can be done iteratively or recursively. Can you get both solutions?<jupyter_code>class Node:
    def __init__(self, value, next_node=None):
        self.value = value
        self.next_node = next_node

    def __str__(self) -> str:
        pointer = self
        nodes = list()
        while pointer is not None:
            nodes.append(pointer.value)
            pointer = pointer.next_node
        return ' -> '.join(nodes)
def iteratively_reverse(linked_list: Node) -> Node:
    pointer_A = linked_list
    pointer_B = None
    while pointer_A is not None:
        pointer_B = Node(pointer_A.value, pointer_B)
        pointer_A = pointer_A.next_node
    return pointer_B
def recursively_reverse(linked_list: Node) -> str:
    if linked_list.next_node is None:
        return linked_list.value
    else:
        return Node(
            recursively_reverse(linked_list.next_node),
            Node(linked_list.value)
        ).__str__()
print(
    iteratively_reverse(
        Node('4', Node('3', Node('2', Node('1', Node('0')))))
    )
)
print(
    recursively_reverse(
        Node('4', Node('3', Node('2', Node('1', Node('0')))))
    )
)<jupyter_output>0 -> 1 -> 2 -> 3 -> 4
0 -> 1 -> 2 -> 3 -> 4
{'fraction_non_alphanumeric': 0.12175792507204611, 'fraction_numerical': 0.01729106628242075, 'mean_word_length': 2.7238605898123325, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '404578', 'license': 'MIT', 'n_tokens_mistral': 464, 'n_tokens_neox': 450, 'n_words': 111, 'path': 'January/Week1/6.ipynb', 'repo_name': 'Dragon1573/Daily-Problem', 'size': '1388'}