18. Using a list of lists in a function
From what I understood from previous sections of this course, the use of the "for x in y" could also be written as "for x in range(len(y))" for use when itterating through loops. Indeed I have returned through the previous examples which also used listsof integers and had no issues in itterating through those lists.
I have since searched through the forums and seen that everyone has used "for x in y" format, though I do not understand why that would work and not the "range(len(y))". Either I've missed something obvious or there's a blank-spot in a part of the course setting out the limits of what the "range(len(y))" version can do.
Traceback (most recent call last): File "python", line 25, in <module> File "python", line 19, in flatten TypeError: object of type 'int' has no len()
My biggest confusion being that the TypeError saing "object of type 'int' has no len()". From my understanding, each of the objects being handed into the For loops are lists ("lists" and "numbers" respectively), both of which have a definite length in the array.
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)