A Qualcomm Snapdragon processing pipeline stores ordered work items in a singly linked list. Given the head of the list, reverse the list in place and return the new head.
You must change the existing next pointers rather than creating replacement nodes. The list nodes are represented by ListNode objects with an integer val field and a next field containing another node or None.
Implement reverse_list(head), where head is either the first ListNode or None. Return the ListNode that becomes the first node after reversal. The input list contains no cycles.
def reverse_list(head):