Using a list of lists in a function


#1



Here is the exercise.


I am getting the error Oops, try again. flatten([[1, 2], [3, 4]]) returned [[[1, 2], [3, 4]], [[1, 2], [3, 4]]] instead of [1, 2, 3, 4]t


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



print flatten(n)

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


#2

Hi, @javaninja03459 ,

What role does numbers play in this outer loop header?

for numbers in lists:

You may want to have the inner loop process that object.


#4

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