indexing - Python - list index out of range with arrays -


basically want create outputs me new created lists.

def map(mines, layers):     mine_distance = []     mine_sector = []     in range(layers):         if mines[i][0] != 0 , mines[i][1] != 0:             mine_distance.append(mine_distance[i][0])             mine_sector.append(mine_sector[i][1])     print(mine_distance, mine_sector)  map([[2, 4], [2, 1]], 5) 

but error:
indexerror: list index out of range

the output should : [2, 2] [4, 1]
can me?

i guess should corrected as:

mine_distance.append(mines[i][0]) mine_sector.append(mines[i][1]) 

previously trying access (mine_distance.append(mine_distance[i][0]), empty @ point of time) element of empty list, , hence getting indexoutofbounds error.

another reason indexoutofbounds error inequality in len(mines) , layers, should either pass layer argument = len(mines) or should change loop for in range(len(mines)):


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -