Two Pointers Moving in Parallel

please kindly help advise , under the function def nth_last_node , since we defined current = None , to my understanding , since i dont see there is no anyother code about “current” , so current will be always “None”. so the else will never be executed since “if current is None” will always be executed.

from LinkedList import LinkedList

# Complete this function:
def nth_last_node(linked_list, n):
  current = None
  tail_seeker = linked_list.head_node
  count = 1
  while tail_seeker:
    tail_seeker = tail_seeker.get_next_node()
    count += 1
    if count >= n + 1:
      if current is None:
        current = linked_list.head_node
        current = current.get_next_node()
  return current

def generate_test_linked_list():
  linked_list = LinkedList()
  for i in range(50, 0, -1):
  return linked_list

# Use this to test your code:
test_list = generate_test_linked_list()
nth_last = nth_last_node(test_list, 4)

there’s stuff changing that value of current later in the function (inside the while loop).

but as i said since we initiate the value of current as none , “else” in loop will be never executed .

ok …

      if current is None:
        current = linked_list.head_node
        current = current.get_next_node()

consider … current starts out being None,
so the stuff in the block after
if current is None:
the next thing to run is
current = linked_list.head_node
and linked_list.head_node is not None
after this line runs,
current is not None anymore
in that iteration of the loop.
there’s nothing else to change the value of current in the loop,
so on the next iteration of the loop,
the value of current is not None (it is the value from the linked_list.head_node);
so the else-block runs.

THANKS …i missed the contents in “if”.