#18 - Alternative solution?


#1

Hey guys,

Ive got a question, I used the following code to get the correct result:

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

Add your function here

def flatten(lists):
results = []
for numbers in lists:
results = results + numbers
return results

print flatten(n)

Do you guys see any problem with the fact I didn't use an additional loop? Could the code break in a different case?

Thank u.

  • edit - intended properly, the spaces got like that while doing copy - paste.

#2

@vladidudegmail.com: You understood that your code will iterate through all elements of your bigger list, n, which contain the other lists so as long as you follow the instructions, things are fine.


#3

Thank you!

(Too short)