18. Lists and Functions


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/4/2?curriculum_id=4f89dab3d788890003000096

Thanks in advance for any help. The code works perfectly in that it returns the output that I want, but it returns the following error message:

Oops, try again. flatten([[1, 2], [3, 4]]) returned [1, 2, 3, 4, 5, 6, 7, 8, 9] instead of [1, 2, 3, 4]


The hint makes it appear as though it is fine though:

[[1, 2, 3], [4, 5, 6]]
into

[1, 2, 3, 4, 5, 6]

<do not remove the three backticks below>

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
    results = []
    for numbers in n:
        for x in numbers:
            results.append(x)
    return results


print flatten(n)

The output is:

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


#2

this for loop:

for numbers in n:

you shouldn't use n here, you can pass n as argument into the function, then you use the function parameter (lists), this way you can use your function many times