结果是嵌套列表,看起来像这样:蟒蛇地图功能迭代
>>> results
[[1, 2, 3, 'a', 'b'], [1, 2, 3, 'c', 'd'], [4, 5, 6, 'a', 'b'], [4, 5, 6, 'c', 'd']]
PR是一个函数,以定义是这样的:
>>> def pr(line):
... print line
成果师范大学迭代确实表现得像这样:
>>> for result in results:
... pr(result)
...
[1, 2, 3, 'a', 'b']
[1, 2, 3, 'c', 'd']
[4, 5, 6, 'a', 'b']
[4, 5, 6, 'c', 'd']
但隐迭代地图,导致这种行为:
>>> map(pr, results)
[1, 2, 3, 'a', 'b']
[1, 2, 3, 'c', 'd']
[4, 5, 6, 'a', 'b']
[4, 5, 6, 'c', 'd']
[None, None, None, None]
我的问题:为什么map函数会产生额外的迭代?
'map'来自函数式编程语言http://en.wikipedia.org/wiki/Map_%28higher-order_function%29它不应该像这样使用 – jamylak
@jamylak:pr是一个演示函数问题,我在我的代码中应用了其他一些转换。 –