Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t在map()上使用len()_Python - Fatal编程技术网

Python Can';t在map()上使用len()

Python Can';t在map()上使用len(),python,Python,解释器说map类型的对象没有长度。如何知道用户输入的数字?您需要将map对象转换为列表,因为map类似于生成器,只根据需要生成值 或者,可能更具可读性,使用列表理解: c = input("Enter a list of number seperate by ','\n") d = list(map(int, c.split(","))) print(sum(d)/len(d)) 或者,您可以稍微重新构造代码,因为str.split()会提供一个列表: c = input("Enter a

解释器说map类型的对象没有长度。如何知道用户输入的数字?

您需要将
map
对象转换为
列表,因为
map
类似于生成器,只根据需要生成值

或者,可能更具可读性,使用列表理解:

c = input("Enter a list of number seperate by ','\n")
d = list(map(int, c.split(",")))
print(sum(d)/len(d))

或者,您可以稍微重新构造代码,因为
str.split()
会提供一个列表:

c = input("Enter a list of number seperate by ','\n")
d = [int(x) for x in c.split(",")]
print(sum(d)/len(d))

c=input(“输入一个以“,”\n)分隔的数字列表”).split(“,”)\p>您需要将
map
对象转换为
list
,因为
map
就像一个生成器,只根据需要生成值

或者,可能更具可读性,使用列表理解:

c = input("Enter a list of number seperate by ','\n")
d = list(map(int, c.split(",")))
print(sum(d)/len(d))

或者,您可以稍微重新构造代码,因为
str.split()
会提供一个列表:

c = input("Enter a list of number seperate by ','\n")
d = [int(x) for x in c.split(",")]
print(sum(d)/len(d))

c=input(“输入一个以“,”\n)分隔的数字列表”).split(“,”)\p>您需要将
map
对象转换为
list
,因为
map
就像一个生成器,只根据需要生成值

或者,可能更具可读性,使用列表理解:

c = input("Enter a list of number seperate by ','\n")
d = list(map(int, c.split(",")))
print(sum(d)/len(d))

或者,您可以稍微重新构造代码,因为
str.split()
会提供一个列表:

c = input("Enter a list of number seperate by ','\n")
d = [int(x) for x in c.split(",")]
print(sum(d)/len(d))

c=input(“输入一个以“,”\n)分隔的数字列表”).split(“,”)\p>您需要将
map
对象转换为
list
,因为
map
就像一个生成器,只根据需要生成值

或者,可能更具可读性,使用列表理解:

c = input("Enter a list of number seperate by ','\n")
d = list(map(int, c.split(",")))
print(sum(d)/len(d))

或者,您可以稍微重新构造代码,因为
str.split()
会提供一个列表:

c = input("Enter a list of number seperate by ','\n")
d = [int(x) for x in c.split(",")]
print(sum(d)/len(d))
c=input(“输入一个以“,”\n)分隔的数字列表”).split(“,”)\p>您正在使用python3,其中
map
不再返回
list
,而是返回
map
对象。 使用
list(map(…

您正在使用python3,其中
map
不再返回
list
,而是返回
map
对象,将其显式转换为列表。 使用
list(map(…

您正在使用python3,其中
map
不再返回
list
,而是返回
map
对象,将其显式转换为列表。 使用
list(map(…

您正在使用python3,其中
map
不再返回
list
,而是返回
map
对象,将其显式转换为列表。 使用
list(map(…