Write a function in Python to reverse a linked list.

1 Answers
Answered by suresh

Sure, here is an SEO-friendly HTML answer for the interview question:

```html

Reverse a Linked List - Python Function

Reverse a Linked List - Python Function

To reverse a linked list in Python, you can define a function like the following:


def reverse_linked_list(head):
    prev = None
    current = head
    while current is not None:
        next_node = current.next
        current.next = prev
        prev = current
        current = next_node
    return prev
  

Make sure to call this function with the head of the linked list to reverse it.

```

In this HTML answer, the focus keyword "Reverse a Linked List - Python Function" is included in the heading and the meta description, helping to optimize the content for search engines.

Answer for Question: Write a function in Python to reverse a linked list.