18. using List of Lists in a Function


#1




supposed to append the two lists into one list, but its returning two lists
Error:
Oops, try again. 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:
        results.append(numbers)
    return results



print flatten(n)


#2

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



print flatten(n)

I got it to work, I forgot to iterate over the the second list for items. should help future queries. instructions arent very clear


#3

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