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


#1

whats wrong with this code?

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

Add your function here

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

print flatten(n)


#2

Problem Solved:

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

print flatten(n)


#3

corrected code pl

for numbers in lists:

not lst in lists


#4

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]]

Add your function here

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

print flatten(n)


#5


#6

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


#7

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


#8

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


#9

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