Recently I encountered the following multiple assignment, and have no idea how it swaps two nodes. I want to swap two nodes in a linked list. The code is :
head, head.next = head.next, head
as seen on https://leetcode.com/problems/swap-nodes-in-pairs/discuss/171788/Python-or-Dummynode
Can someone break down the steps and tell me how that code swaps head and head.next? It's very confusing to me.
head.nextand head which are on the right side the=. then assigns them to variables on the left side of=respectively.