18 using a list in a function


#1

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

Add your function here

def flatten(lists):
results=[]
for numbers in lists:
for number in numbers:
results.append(number)
return results

print flatten(n)

with the correct indentations.


#2

Hi your code works fine but it maybe a indent problem so here the code with the correct indentation

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

    def flatten(lists):
        results=[]
        for numbers in lists:
            for number in numbers:
                results.append(number)
        return results

    print flatten(n)

#3

The reason is when you write return below first from bottom for loop. It only returns result of first for loop. When you ident it according to first for loop from top it returns everything.

Test it yourself to see it visually.


#4

This code worked for me:
It took me a while because my indentation was incorrect.


#5

thank you so much i had this exercise correct for an hour but the indentation was blowing my mind, even after seeing yours
Here is what worked for me
18ListonaList