18/18 Using a ist of lists in a functioh


#1



Console gives a bunch of numbers(1,2,3 only a lot of times.)
Error : Oops, try again. flatten([[1, 2], [3, 4]]) returned [1, 2, 1, 2, 3, 4, 3, 4] instead of [1, 2, 3, 4]
BTW i don't understand a thing bout range.Any help for my problem and explanation for range would be awesome.
Thanks


n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
    results = []
    for numbers in lists:
        for item in numbers:
            results += numbers
    return results    



print flatten(n)


#2

you need to append to empty list results, use .append()

print range (0, 8)
you'll get numbers from 0-7, meaning your range starts from 0 and it's done before 8
print range (2, 12) will print 2-11

you can add third number, third number is step, if you put 2 as third number it will print every second number


#3

No change.Same result


#4

copy your code with append


#5

n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
    results = []
    for numbers in lists:
        for item in numbers:
            results.append(numbers)
    return results    



print flatten(n)

#6

you need to put item, .append(item)

do you know how for loop works?


#7

Is it necessary to give to for statements ? If so, why?


#8

guess you wanted to say ...to give two...
do you have different idea?

if you want to know what each for loop does you can put print after each, that's good way to debug your code