Embercode
✕
Linked ListsQuick quiz

Sentinels and removal in Python

8 questions. Covers Remove every occurrence of a value in Python.

Questions 1 to 5 of 8

  1. 1. The remove_careless function below raises an AttributeError when it is called on the first node of a plain doubly linked list. Why? ``python def remove_careless(node): node.prev.next = node.next node.next.prev = node.prev ``
  2. 2. Using the CircularList class from this lesson, what does this code print? ``python lst = CircularList() lst.add_last(3) lst.add_first(1) lst.add_last(5) node = lst.find(5) lst.remove(node) lst.add_first(5) print(f"{lst} size={lst.size}") ``
  3. 3. This loop should print every real value in a CircularList. What is wrong with it? ``python cur = lst.sentinel.next while cur is not None: print(cur.value) cur = cur.next ``
  4. 4. Python has no final keyword for attributes. So the rule that self.sentinel is set once in __init__ and never assigned again is kept by ____ . Fill in the blank.

    Type your answer.

  5. 5. Using the CircularList class from this lesson, which state is an empty list in, right after CircularList() runs?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.