Error in Python List Ops test for concatenate()? (UPDATE: Cleared)

I’m wondering if there’s an error in the test.

The instruction reads:
concatenate Given a series of lists, combine all items in all lists into one flattened list.

For input [[[1], [2]], [[3]], [[]], [[4, 5, 6]]] my code returns [1, 2, 3, 4, 5, 6] which I understand to be one flattened list.

However, looking at the test:

def test_concat_list_of_nested_lists(self):
        self.assertEqual(
            concat([[[1], [2]], [[3]], [[]], [[4, 5, 6]]]),
            [[1], [2], [3], [], [4, 5, 6]],
        )

…it appears that the output is supposed to be a list of lists. Plus I’m not sure if the comma in front of the last parenthesis is intentional?

My code:

def concat(lists):
    result = []
    for item in lists:
        if isinstance(item, list):
            result.extend(concat(item))
        else:
            result.append(item)
    return result

Thanks much for guidance on this.

This is not so much a mistake as just confusing language.

The input to concat is a list of lists of stuff, and the output should be a list of stuff. The stuff itself is not to be ‘flattened’ – in fact it shouldn’t be looked at at all.

So are you saying that for the lists of stuff ignore everything with an index > 0, or in other words, just return the “heads” of each of the lists contained in the list?

The expected behavior is for the function to take a list of lists and concatenate those lists without examining their contents. No recursive flattening, no filtering, no selection. Just add all the provided lists together into a single list.

>>> concat([[a], [b], [c]])
[a, b, c]

as in [[[1], [2]], [[3]], [[]], [[4, 5, 6]]] returns [1, 2, 3, 4, 5, 6]? Or rather [1, 2, 3, 0, 4]?

>>> concat([[[1], [2]], [[3]], [[]], [[4, 5, 6]]])
[[1], [2], [3], [], [4, 5, 6]]

Thanks Isaac and Matthijs, I could’t see the forest for the trees. :evergreen_tree::evergreen_tree: