Question 6
Back to Exercise
The pages should be listed in the order they were first visited: 5, 3, 1. Which statement correctly identifies the bug?
visits = [5, 3, 5, 1, 3]
unique = list(set(visits))
print(unique)
- A list() sorts its argument
- B A set does not keep insertion order; use list(dict.fromkeys(visits)) to remove duplicates in order Correct
- C set() removes the wrong items
- D visits must be a tuple
Correct Answer: Option B
Small ints happen to come out ascending here; strings may come out in any order. Never rely on set order.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!