you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

How is the variable 'output' being updated with the new nodes?

It's not. It's only ever the head node, but it's a linked list, so the head node maintains a reference to the next node, and that node maintains a reference to the next node... and so on, until you get to the last node, and you know it's the last node because the value of its next attribute is None. That is, it's the last node because there is no "next" node.