Using lists of lists in a function


#1

Hi all,
I am having some problems with this lesson, but I don't fully understand my error....

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(item)
    return results        
print flatten(lists)

Traceback (most recent call last):
  File "python", line 9, in <module>
  File "python", line 6, in flatten
TypeError: 'int' object is not iterable

Line 9 is print flatten(lists)
and line 6 is for numbers in lists:

If someone could please explain the ''int' object is not iterable' part to me I think that I would understand more as to why my code doesn't work. I don't understand where the 'int' comes in, because there are no integers used in lines 6 or 9.
Thank you!


#2

the problem is here:

print flatten(lists)

lists is undefined, supply n as argument instead which then gets copied into the function parameter lists


#3

Thanks for the assistance; the code worked.


#4