0

Im having problems indexing a 6x6 matrix in which i created through nested lists. The program is for a flipping tiles game if that helps for visualization. The matrix looks something like this:

[["word1","word2","word3,"word4","word5","word6"],["word7", ... etc] 

with 6 rows and 6 elements in each row.

I would like to assign each word to an combination of two elements with the two lists ["A","B","C","D","E","F"] on a (horizontal axis) and ["1","2","3","4","5","6"] on a (vertical axis), for example "word1" would be assigned to "A1". The word in question would then be accesed through an input from a user through this number/letter combination, so that i can change the matrix based on their input.

Right now i have some spaghetti code.

for i in range(6):
    listVertical[0]+listHorizontal[i] == wordList[0[i]]
    listVertical[1]+listHorizontal[i] == wordList[1[i]]
    listVertical[2]+listHorizontal[i] == wordList[2[i]]
    listVertical[3]+listHorizontal[i] == wordList[3[i]]
    listVertical[4]+listHorizontal[i] == wordList[4[i]]
    listVertical[5]+listHorizontal[i] == wordList[5[i]]

But im mainly wondering if this is even possible at all with the outline that i have right now or if i need to think of another way.

Its for a school project and the main help i found are through numpy and other libraries, which im not familiar with and not sure if we're allowed to use.

gog
  • 10,367
  • 2
  • 24
  • 38
  • 1
    Why not a dictionary of dictionaries rather than a list of lists? – John Coleman Nov 13 '22 at 13:17
  • I started off with lists and during the feedback session the assistant said that it was fine, i also have more experience with lists so therefore i took this route. – Jeffery Nov 13 '22 at 13:30
  • You could keep what you have and create a dictionary (perhaps called `index`) which maps things like `'A'` to `0`, etc. and then use something like `words[index['3']][index['B']]` -- but it would ultimately be more readable if you make everything a dictionary. – John Coleman Nov 13 '22 at 13:37

0 Answers0