简体   繁体   English

我想打印 Python map 列表元素

[英]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.

相关问题 我想打印列表中添加的所有元素,但它只打印最后一个元素。(Python) - I want to print all the element added in list but it is only printing the last element.(Python) 我想在列表中打印每个单词以及该单词/元素的相应出现 - I want to print each word and respective occurrence of that word/element in a list 我想从 python 的列表中打印唯一的字符串,但它破坏了列表 - I want to print unique strings from a list in python but it breaks the list Python:我有一个列表,我想将它添加到列表的每个元素中 - Python: I have a list and I want to add it to each element of the list 如果在列表中(我想向列表中的元素添加一些东西) Python - if a in list (I want to add something to the element in list) Python 我想在python 3的文本文件中搜索列表元素 - I want to search list element in the text file in python 3 我如何从python中的列表中随机打印元素 - how can i randomly print an element from a list in python 如何打印此Python列表的每个元素? - How can I print each element of this Python list? 我如何在充满行的列表中打印每个第二个元素? Python - How i print each second element in a list full of lines? Python 我想分别访问列表列表的元素(心形网格)并以正确的方式打印心形 - I want to individually access element of my list of lists (heart grid) and print the heart the correct way up
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM