Object is not subscriptable

I am running into issue with my code, it does not pass the check and I receive the following:

Your code didn’t print anything.

Expected Correct Output
4 5 1 2 3

Execution failed.
TypeError : ‘map’ object is not subscriptable

Stack Trace:
Traceback (most recent call last):
File “/hackerearth/PYTHON3_5a8c_5f3d_8e23_3dcf/s_cb41_69bc_c648_ad7d.py3”, line 7, in
TypeError: ‘map’ object is not subscriptable

I was hoping someone could help me fix my code and understand the meaning of the errors.

t = int(input())
while t!=0:
	n,k = map(int, input().split())
	arr = map(int, input().split())
	index = n - (k%n)
	for i in range(index, n):
	for i in range(index):

When you use map function the returned value is not a list as you suppoused, but a map object.
You can convert it to a list with a list function.
So try changing arr = map(int, input().split()) to arr = list(map(int, input().split())).

If you try googling for this you may find answers that advise iterating over a map. It doesn’t really fit your need because:

  • you can’t get access to arbitraryelement from it
  • when you iterate all objects and go to the for i in range(index) you will get nothing (all objects already consumed)

Some useful links:

Also check that in for loops you type i and not I as you will get NameError because I varriable doesn’t exist.