flat([[1,2,3],[4,5,6],[7,8,9]]) = [1,2,3,4,5,6,7,8,9]
def flat(nestedlist):
outcome = []
请问怎么做
return outcome
按照你的要求编写的Python程序如下
def flat(nestedlist):
outcome = [nestedlist[i][j] for i in range(len(nestedlist)) for j in range(len(nestedlist[i]))]
return outcome
print(flat([[1,2,3],[4,5,6],[7,8,9]]))
源代码(注意源代码的缩进)