Sorted distinct values
A table contains integer measurements. The function in Listing 1 retains only values from 1 through 10, removes duplicates, and returns its result in ascending order.
sorted returns a list in ascending order.
What is printed by Listing 1?
[1, 2, 7, 9, 10][7, 2, 11, 10, 1, 2, 9][2, 0, 0, 0, 0, 0, 2, 0, 1, 1][7, 2, 11, -1, 10, 1, 2, 9, 7, 0, -1]
TipHint
bounded_distinct(table)receives a nested list of integers and returns a sorted list of distinct values in the inclusive range1through10. For example,bounded_distinct([[3, 3, 12]])returns[3], andbounded_distinct([])returns[].set()creates an empty set.found.add(value)adds a value and returnsNone; adding4twice still leaves only one4in the set.sorted(values)returns a new list in ascending order without changing the input:sorted({4, 2})is[2, 4].print(value)displays the value and ends with a new line.