educative.io

Reverse linked list

Isn’t it better for reverse linked list to be done in more concise code:

  node, prev = head, None
  while node:
    t, node.next = node.next, prev
    prev, node = node, t

  return prev

Not necessarily. While concise and clean code is often a good thing to strive for, I would caution against sacrificing readability. In this case, your code is extremely concise, but not super clear what is going on.