1

for taking list input in the array I used

map(int,input().split())

but for using this input method I can't modify the array if I Iterated like a[I] then it shows

TypeError: 'map' object is not subscriptable

Can you please tell me how can I resolve this problem? I am a competitive programmer but I am new to python I must have take input array by using map(int,input().split())

Ahsan Amin
  • 45
  • 5

2 Answers2

1

Use list(map(int,input().split())) instead of map(int,input().split()) to convert your input to list, because map function returns an generator which can not be indexed.

Ratery
  • 2,863
  • 1
  • 5
  • 26
  • Thank you so much.. but can you tell me what's wrong in without list? – Ahsan Amin Dec 10 '21 at 14:46
  • 1
    `map` function returns an generator. Generator can not be indexed like `x[i]`. Read more about generators in python [here](https://wiki.python.org/moin/Generators). – Ratery Dec 10 '21 at 14:50
1

If you can't use another function like list, use:

# Input: 1, 2, 3, 4, 5
l = [*map(int, input().split())]
print(l)

# Output:
1 2 3 4 5
Corralien
  • 109,409
  • 8
  • 28
  • 52