Nested-list processing

In Listing 1, the Python function x receives a non-empty two-dimensional list of integers and returns a list.

Listing 1: A Python function that processes two-dimensional integer data (Question 1).
def x(data):
    present = [False] * 11

    for row in data:
        for value in row:
            if type(value) is int and 1 <= value <= 10:
                present[value] = True

    result = []

    for value in range(1, 11):
        if present[value]:
            result.append(value)

    return result

Considering the two-dimensional list in Table 1, what is returned when x is called with that list?

Table 1: Input data (Question 1).
A B C D
1 7 2 11 10
2 11 1 2 1
3 9 7 0 -1

What is the returned list?

  • [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]
  • range(start, stop, step) supplies integers from start toward, but excluding, stop.

    • step defaults to 1, and range(stop) starts at 0.
    • list(range(2, 7, 2)) is [2, 4, 6]; list(range(5, 1, -2)) is [5, 3].
    • A range is empty when the step cannot reach the stop; a zero step raises ValueError.
  • list collects the supplied values in a new list.

  • items.append(value) adds one item at the end of the list and returns None. Starting with items = [8], items.append(3) changes it to [8, 3]. An appended list remains one nested item; an empty list accepts its first item the same way.