M1) Number or not?

In Listing 1, we have four versions of a Python function split_values_per_type that receives a list of values and splits them into two lists: one with the numbers and another with the non-numbers. The function should return the two lists as the tuple (numbers, non_numbers).

For this question, a value is numeric exactly when type(value) in (int, float) is True. Therefore, integers and floating-point values are numeric, while strings and Boolean values are non-numeric.

Listing 1: Alternative implementations of a Python function that splits a list into numeric and non-numeric values and returns both resulting lists (Question 1).
(a) Implementation 1.
def split_values_per_type(values):
    numbers = []
    non_numbers = []

    for value in values:
        if type(value) in (int, float):
            numbers.append(value)
        else:
            non_numbers.append(value)

        return numbers, non_numbers
(b) Implementation 2.
def split_values_per_type(values):
    for value in values:
        numbers = []
        non_numbers = []

        if type(value) in (int, float):
            numbers.append(value)
        else:
            non_numbers.append(value)

    return numbers, non_numbers
(c) Implementation 3.
def split_values_per_type(values):
    numbers = []
    non_numbers = []

    for value in values:
        if type(value) in (int, float):
            numbers.append(value)
        else:
            non_numbers.append(value)

    return numbers, non_numbers
(d) Implementation 4.
def split_values_per_type(values):
    numbers = []
    non_numbers = []

    for value in values:
        if type(value) in (int, float):
            numbers.append(value)
        else:
            numbers.append(value)

    return numbers, non_numbers

Which implementation of split_values_per_type in Listing 1 correctly splits every input value and returns (numbers, non_numbers)?

  • split_values_per_type(values) must return its two result lists as a tuple. For example, input [2, "X"] should produce ([2], ["X"]); empty input should produce ([], []).
  • type(value) returns the value’s type: type(2) is int, type(2.5) is float, and type(True) is bool.
  • values.append(item) adds one item to the end of that list and returns None. For example, appending "B" to ["A"] changes it to ["A", "B"].