Using a List of Functions


#1

Ok, so for some reason:

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

def flatten(lists):
results = []
for numbers in lists:
results.extend(numbers)
return results
print flatten(n)

This works, whereas

def flatten(lists):
results = []
for numbers in lists:
results.extend(numbers)
return results
print flatten(n)

This does not.

And the bar on the left tells you to 'append', not 'extend.'
Why?


#2

Check out this forum.

Also, this is your function.

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

This is calling the function print flatten(n). Which, when n is defined, is equal to print flatten([[1, 2, 3], [4, 5, 6, 7, 8, 9]]), but when n isn't defined it is equal to print flatten(some random set of letters that mean nothing to a computer)