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 6,154 views

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

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

## Size is (121,512,512). Error is coming as : IndexError: index 152 is out of bounds for axis 0 with size 121.

def nodule_detect(nodules,j,numpyImage, numpyOrigin, numpySpacing): ...READ MORE

## How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

–1 vote

## How to filter out any digit that contains odd number in a range of number in Python?

n = list(range(10)) b = list(filter(lambda i:i%2!=0,n)) print(b) READ MORE

## How do I obtain the index list in a NumPy Array of all the NaN values present using Python?

Hi, it is pretty simple, to be ...READ MORE

## Is there a way to list out in-built variables and functions of Python?

The in-built variables and functions are defined ...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