class Solution(object):
def reverseBetween(self, head, m, n):
"""
:type head: ListNode
:type m: int
:type n: int
:rtype: ListNode
"""
dummyhead = ListNode(0)
dummyhead.next = head
p = dummyhead
i = 0
while i < m  1:
p = p.next
i += 1
tail = p.next
while i < n  1:
x = p.next
y = tail.next
p.next = y
tail.next = y.next
y.next = x
i += 1
return dummyhead.next
clean python solution


@mwx36mwx Excellent solution, but I wish you hadn't named the variables so succinctly.
