Using a list of lists in a function


Oops, try again. flatten([[1, 2], [3, 4]]) returned None, did you remember to return the result?

I am not sure what I did wrong. Please help me!

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

print flatten(n)


Remove return from this line..
return results.append(lists)

Reason of error:
Whenever a function hits return keyword it abandons other lines of code after it and leaves function!


Thank you! I could solve it.


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