Question 11
Back to Exercise
What is the output of the following Python program?
nums = [3, 1, 3, 2, 1]
print(list(dict.fromkeys(nums)), sorted(set(nums)))
- A [3, 1, 2] [1, 2, 3] Correct
- B [1, 2, 3] [1, 2, 3]
- C [3, 1, 2] [3, 1, 2]
- D [3, 1, 3, 2, 1] [1, 2, 3]
Correct Answer: Option A
dict.fromkeys keeps the first-seen order; sorted(set(…)) gives the unique values in ascending 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!