Python Can';t在map()上使用len()
解释器说map类型的对象没有长度。如何知道用户输入的数字?您需要将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
类似于生成器,只根据需要生成值
或者,可能更具可读性,使用列表理解:
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(…