Question 21
The following Python expression is entered into a fresh Python shell with no prior import statements. Determine the result from evaluating the following expression. [3 marks]
Solution
Let's look at the following expression:
The set() function turns any iterable into a set, but it eliminates any duplicate elements inside it.
Sets can be regarded as a collection of unique elements (i.e., non-repeating).
Here, this expression turns list [3, 4, 7, 6, 0, 0, 1] into set {3, 4, 7, 6, 0, 1}, removing the duplicate 0 from the input list.
Note
Each time you print a set, the elements may appear in a different order from the previous run. For simplicity, the original order will be maintained or an ascending order will be deployed.