Skip to content

Question 22

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]

print(len({(1, 3), (3, 5), (5, 7), 9}))
Solution

Let's look at the set we are trying to get the length of here:

{(1, 3), (3, 5), (5, 7), 9}

The elements in the tuple are as follows: (1, 3), (3, 5), (5, 7), 9. Elements (1, 3), (3, 5) and (5, 7) count as 1 element each, since on the same surface level, these tuples are 1 unit. In other words, we do not deep dive into each atomic element inside this whole tuple.

This then means that there are 4 elements in total, hence the given expression results as 4.

Answer
4