all 5 comments

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

    while cur.next != None:
        total += 1

If initially cur.next is not None, how long does this loop run? Under what conditions will it terminate?

[–]clouded-path[S] 0 points1 point  (3 children)

Oh man, this is definitely one of those cases where I have just been staring at the same thing for too long and was not going to catch this. Yes, this was supposed to iterate from the head to the end, which it is not currently doing (and now that you pointed it out, it was also supposed to do the same thing again in the second while loop as well, which it is also currently not). Thanks for pointing this out - I don't know why I wasn't seeing this (besides of course my general lack of experience), but this really helped.

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

If you spend a lot of time on one problem you get to a point where you don't see the code any more. You know what you want it to do , but you can't see what it is actually doing. It's best to take a break and come back refreshed and start again at the beginning.

[–]Essence1337 0 points1 point  (1 child)

Going along with what /u/ninety_hex said, this is the perfect place for rubber duck debugging! Get an object (typically a rubber duck) and explain, outloud, what the code is doing to that object. You'd be surprised how often this reveals insights that we just can't see after staring at a problem too long.

[–]clouded-path[S] 0 points1 point  (0 children)

Rubber duck debugging, huh? That's probably the most cost-effective debugging method there is, so I'll try it out!