I am trying to execute the following python code:

```def construct(s, k, a):
index = 0
# Finding the index which is not -1
for i in range(s):
if (a[i]!=-1):
index = i
break
# Calculating the values of the indexes index-1 to 0
for i in range(index-1, -1, -1):
if (a[i]==-1):
a[i]=(a[i + 1]-1 + k)% k
# Calculating the values of the indexes index + 1 to n
for i in range(index + 1, s):
if(a[i]==-1):
a[i]=(a[i-1]+1)% k
print(a)
# Driver code
s, k = 6, 7
a = [1, 2, 3, 4, 5]
construct(s, k, a)```

I get the following error:

`IndexError: list index out of range`
Jun 17, 2019 in Python 7,162 views

## Error: IndexError: list index out of range and python

IndexError The IndexError is raised when you attempt to retrieve ...READ MORE

## how to solve this IndexError: list index out of range in python and streamlit?

Hi,  @Erick, To solve the “index error: list ...READ MORE

## Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?

I am assuming that you have a ...READ MORE

## Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?

IndexError occurs when the item you want ...READ MORE

## Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?

I'm telling my program to print out ...READ MORE

## Does "IndexError: list index out of range" when trying to access the N'th item mean that my list has less than N items?

I'm instructing my software to print out ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE