A My Disney Experience itinerary is represented as a singly linked list of activity nodes. Given the list head, swap every two adjacent nodes and return the new head. The nodes themselves must be rearranged by changing pointers, not by changing their stored values.
If the list contains an odd number of nodes, leave the final node in its original position.
Define ListNode with an integer val field and a next pointer. Implement reverse_pairs(head), which accepts either None or the head of a singly linked list and returns the head of the pairwise-swapped list. Test cases below represent linked lists as arrays of node values. The test harness converts each input array into a linked list and converts the returned list back to an array.
def reverse_pairs(head):