简体   繁体   中英

python 2d matrix manipulation need help without numpy

i want to "pop" a spot in a 2D array in python the code:

w, h = 8, 8;
Matrix = [["#" for x in range(w)] for y in range(h)] 


for w in Matrix:
    for h in w:       
     print("#",end = " ")
    print()




numA = int(input())
numB = int(input()) 

Matrix.pop(numA - 1)(numB - 1) #the part i need help with**
Matrix[numA - 1][numB - 1] = J = 1

for w in Matrix:
    for h in w:       
     print("@",end = " ")
    print()

it doesnt work. what's wrong with the code?

pop only works on a list - ie. in your case on a row. So:

Matrix[numA - 1].pop(numB - 1)

will remove numB th element from numA th row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM