Using a list of lists in a function


#1

My question is around question 18 in this section. Correct code is below:

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

Add your function here

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

print flatten(n)

My question is - in a few of the exercises, the singular version of a variable (in this case ‘number’ for ‘numbers’) is somehow integrated into the code. It doesn’t seem like any foundation exists, but maybe I missed something in a lesson? In other words, I didn’t see ‘number’ mentioned in any of the provided code or in the instructions, yet it is part of the correct code. Advice please? Thanks!


#2

It is what one could expect to read in a well thought out program.

 for singular in plural:

As authors, we name the characters of our play.


#3

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