18. Using a list of lists in a function


#1

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

Add your function here

def flatten(lists):
results = []
for numbers in lists:
for i in numbers:
results =+ i
return results
print flatten(n)

this code return the following error:
Oops, try again. flatten([[1, 2], [3, 4]]) returned 4 instead of [1, 2, 3, 4]

someone can help me with it and tell me what's worng?


#2

Hi, @asafrdt ,

What does this statement actually do?

results =+ i

Note that the test case, namely flatten([[1, 2], [3, 4]]), that Codecademy reported, returned 4, which is also the final value in the list that was used in that test.

When you post code, you should format it. See How do I format code in my posts?.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.