What's wrong in this way?


#1

Hi all,

The following code failed with an error
Traceback (most recent call last):
File "python", line 12, in
File "python", line 7, in flatten
TypeError: object of type 'int' has no len()

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

Add your function here

def flatten(lists):
results = []

for numbers in range(len(lists)):
    for number in range(len(numbers)):
        results.append(number)

return results

print flatten(n)

When I changed the code without using range(), it worked.
Why does it take "numbers" to be an integer, rather than a list?

Thanks !


#2

Hi,

That is because the length of a list is an integer.


#3

Thanks, I was probably tired :smile: