我在本书的9.7.1创建生成器qazxsw poi中编写了示例代码
但我没有输出书中输出的内容。
书中的例子:
Beginning Python From Novice to Professional(Third Exdition)
书中的输出:
def flatten(nested):
for sub in nested:
for element in nested:
yield element
nested = [[1,2],[3,4],[5]]
for num in flatten(nested):
print(num)
我的输出与python 3.7.2:
1
2
3
4
5
我的python有什么问题?
第三行应该是[1, 2]
[3, 4]
[5]
[1, 2]
[3, 4]
[5]
[1, 2]
[3, 4]
[5]
for element in sub: