python的怎么打印map和reduce结果

如题所述

在Python2里,直接使用map就可以打印结果

print(map(lambda x:x*2, [1,2,3]))

但是在Python3里,map返回的结果是迭代器(iterator)

需要先转换为列表list

print(list(map(lambda x:x*2, [1,2,3])))

温馨提示:答案为网友推荐,仅供参考