Using a list of lists in a function


#1



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


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)


#2

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!


#3

Thank you! I could solve it.


#5

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