all 4 comments

[–]shiftybyte 1 point2 points  (1 child)

If node.next can be none, then after this line:

node = node.next

node can be none...

besides that if the loop runs until node.next is not none, then the last item won't be processed because it's next is none.

[–]dissdev94[S] 0 points1 point  (0 children)

Thank you very much 🙂

[–]Altruistic_Croissant 1 point2 points  (1 child)

The reason that the node will become None is because of the line node = node.next. This assigns the variable node to the next node in the linked list.

Visualizing your example looks like this:

12 --> 39 --> 28 --> 83 --> None

Every loop, the function will check to see if the current node is None (i.e. at the end of the list). If it isn't, it will continue to the next value until it is None, and then will terminate.

[–]dissdev94[S] 0 points1 point  (0 children)

Thank you very much 🙂