I’m on exercise 18 of ‘Using a list of lists in a function’ and I’m sure my thinking is correct but there’s an error in the actual doing of it!
My code below returns:
flatten([[1, 2], [3, 4]]) returned [1, 2] instead of [1, 2, 3, 4]
My thinking (and reading through these forums I’m not just quitting first time I get stuck!) is that I create my first list which gets all my numbers in one bunch, I then go through that new combined list and append them to my results.
I did think that it was maybe my return was indented incorrectly as is looks below but on the code entry section it is inline with my first for loop (which I think is where it needs to be to get all the numbers).
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]] # Add your function here def flatten(lists): results =  for list_2 in lists: for number in list_2: results.append(number) return results print flatten(n)
Below is my code showing the indentation (I’ve been bitten by this before, it’s not the same as SQL! )