18. list of lists inside a function



So i have succefully completed the lesson, but i have a question as to why i cant complete in a different way. Why cant i complete the program by using a range instead of the list lists?

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

def flatten(lists):
    results = []
    for numbers in range(0, len(lists)):
        for num in numbers:
    return results
print flatten(n)


why does the for loop need to be

instead of


it doesn't, but using range will give you indexes:

example = ['a','b','c','d','e']
for i in range(len(example)):
    print i
    print example[i]
for i in example:
    print i

that should clarify it for you


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.