Jump to content

riad

Members
  • Posts

    1
  • Joined

  • Last visited

riad's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. riad

    2d matrix values

    I have a 2-dimensional matrix, initialized to matrix_height [['-'] * 10] * 10 I replace certain boxes so as to have (visually) this: ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-'] ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-'] when i access tu th value matrix_height[8][0] it gives me : '-' and it's true for all des values accessing individually (and it's that values that i want). whene I print the entire line, matrix_height[8], it gives me that : ['A', 'A', 'A', 'A', '-', '-', '-', '-', '-', '-'] can anyone help me ? thank you matrice_hauteur = [['-']*10]*10 matrice_largeur = [['-']*10]*10 d_d=0 d_c=0 x=8 y=4 print(x,y) print('rr',matrice_hauteur[7:9],d_c) for d_d in range(0,x): for d_c in range(0,y): matrice_hauteur[d_d][d_c]='A' print(d_d,d_c) if d_c==y: break if d_d==x: break for d_d in range(0,10): for d_c in range(0,10): print(matrice_hauteur[d_d-d_c]) print(matrice_hauteur[0-9]) print(matrice_hauteur[1-9]) print(matrice_hauteur[2-9]) print(matrice_hauteur[3-9]) print(matrice_hauteur[4-9]) print(matrice_hauteur[5-9]) print(matrice_hauteur[6-9]) print(matrice_hauteur[7][0],matrice_hauteur[7][1], matrice_hauteur[7][2],matrice_hauteur[7][3], matrice_hauteur[7][4],matrice_hauteur[7][5], matrice_hauteur[7][6],matrice_hauteur[7][7], matrice_hauteur[7][8],matrice_hauteur[7][9]), print(matrice_hauteur[8][0],matrice_hauteur[8][1], matrice_hauteur[8][2],matrice_hauteur[8][3], matrice_hauteur[8][4],matrice_hauteur[8][5], matrice_hauteur[8][6],matrice_hauteur[8][7], matrice_hauteur[8][8],matrice_hauteur[8][9]), print(matrice_hauteur[9-9]) print(matrice_hauteur[8][4]) print(matrice_hauteur[8])
×
×
  • Create New...