Distinct labels in encounter order
In Listing 1, we have a Python function range_to_string that receives a rectangular range represented as a nested list of strings and returns a comma-separated string.
range_to_string that returns the unique values from a two-dimensional list as a comma-separated string. The join method concatenates the strings in unique_values with commas (Question 1).
[["A", "D"], ["1", "1"], ["C", "A"]].
| A | B | |
|---|---|---|
| 1 | A | D |
| 2 | 1 | 1 |
| 3 | C | A |
What is returned by range_to_string when it receives the nested list represented in Table 1?
A,1,C,D,1,AA,1,C,DA,D,1,CA,D,1,1,C,A
TipHint
range_to_string(cell_range)must return distinct labels in the order they are first encountered, one row at a time. For example,range_to_string([["X", "X"], ["Y", "X"]])should return"X,Y".set()creates an empty set.seen.add(value)adds a value once and returnsNone; adding"X"again does not create another member.unique_values.append(value)adds one item to the end of the list and returnsNone.",".join(values)returns the strings joined by commas:",".join(["X", "Y"])is"X,Y", and joining[]returns"".