Spot the bug
Which line misses the case where the first link has the value to remove?
from typing import Anydef drop_value(head: Any, x: int) -> Any:here = headwhile here and here.next:if here.next.val == x:here.next = here.next.nextelse:here = here.nextreturn head
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 5
here = head
Starting at head means only links after the head are ever checked, so a matching head survives. Starting from a placeholder in front of the head fixes it.