[英]I want print Python map list element
I am trying to print a map list element but get the following errors:我正在尝试打印 map 列表元素,但出现以下错误:
inp(i-1)" this is error
and和
inp[i-1]
My code:我的代码:
num, a = map(int, input().split())
inp = map(int, input().split())
for i in range(1,num+1):
if inp(i-1) < a:
print(a)
How can I map the element output?我怎样才能 map 元素 output?
You should convert map obj to a list before indexing.您应该在索引之前将 map obj 转换为列表。
num, a = map(int, input().split())
inp = list(map(int, input().split()))
for i in range(1,num+1):
if inp[i-1] < a:
print(a)
The first line should be changed to two lines:第一行应改为两行:
a = list(map(int, input().split()))
num = len(a)
Also, indexing is used with brackets []
, not parenthesis ()
, so try changing this line:此外,索引与括号[]
一起使用,而不是括号()
,因此请尝试更改此行:
if inp(i-1) < a:
To:至:
if inp[i-1] < a:
So the full code would be:所以完整的代码是:
a = list(map(int, input().split()))
num = len(a)
inp = list(map(int, input().split()))
for i in range(1,num+1):
if inp[i-1] < a:
print(a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.