Using a list of lists in a function


#1



The code seems to fine but it shows the error message that flatten([[1,2],[3,4]]) returned [[1,2],[3,4]] instead of [1,2,3,4]


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.append(i)
    return lists

print flatten(n)


#2

you return lists, but your flattend list is stored in results


#3

Oh man.. silly mistake.. Thanks for the help::+1:


#4

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