 # 18/18 Using a list of lists in a function [Solved]

whats wrong with this code?

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

def flatten(lists):
results =
for lst in lists:
for numbers in lists:
results.append(numbers)
return results

print flatten(n)

1 Like

Problem Solved:

def flatten(lists):
results =
for lst in lists:
for numbers in lst:
results.append(numbers)
return results

print flatten(n)

2 Likes

corrected code pl

``````for numbers in lists:
``````

not lst in lists

1 Like

okay so first you could do for n in lists:
and you dont need to do append your could do results += n for reference heres my code

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

def flatten(lists):
results =
for n in lists:
results += n
return results

print flatten(n)

1 Like
7 Likes

That´s it . I only gave differents names to the variables…
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)

def flatten(lists):
(indent)results =
(indent)for numbers in lists:
(indent)(indent)for value in numbers:
(indent)(indent)(indent)results.append(value)
(indent)return results

1 Like

yes i agree. ppl i want to stress the importance of indenting. a correctly written code will spit out wrong results with improper indenting. practice proper indenting at the beginning so it doesnt bite your butt down the road

did you get pass the question with that??
it doesn’t work for me