python3中运行以下程序,报错
list_1=[1,2,3,4,5,6]
def double_func(x):
return(x*2)
list_2=map(double_func,list_1)
print(list_2)
原因:python3中map()返回iterators类型,不再是list类型。进行list转换即可
list_1=[1,2,3,4,5,6]
def double_func(x):
return(x*2)
list_2=map(double_func,list_1)
print(list(list_2))
运行结果为 [2, 4, 6, 8, 10, 12]