0

So I have a 4 dimensional array, and a really simple function to aid with grabbing elements from said array.

Board=[[
[['K','D','S']  ,  ['T','R','T'] ,  ['X','B','R']],
[['P','P','P']  ,  ['P','P','P'] ,  ['P','P','P']],
[['0','0','0']  ,  ['0','0','0'] ,  ['0','0','0']] 
],[
[['0','0','0']  ,  ['0','0','0'] ,  ['0','0','0']],
[['0','0','0']  ,  ['0','0','0'] ,  ['0','0','0']],
[['0','0','0']  ,  ['0','0','0'] ,  ['0','0','0']] 
],[
[['0','0','0']  ,  ['0','0','0'] ,  ['0','0','0']],
[['p','p','p']  ,  ['p','p','p'] ,  ['p','p','p']],
[['j','r','x']  ,  ['t','r','t'] ,  ['s','d','d']]
]]
def GrabAPeice(title):
    BigLet={'A':0,'B':1,'C':2,'D':3,'E':4}
    SmallLet={'a':0,'b':1,'c':2,'d':3,'e':4}
    BigNum={'5':0,'4':1,'3':2,'2':3,'1':4}
    SmallNum={'5':0,'4':1,'3':2,'2':3,'1':4}
    return Board[BigNum[title[2]]][SmallNum[title[4]]][BigLet[title[0]]][SmallLet[title[1]]]

Where title would be something like 'Aa1:2' respectively

The only problem is when I try to use the function for assignment,

GrabAPeice('Bb2:2')='Q' it does not let me assign a value.

Is it possible to have a function return a reference or an alias to another object in python?

I know about get and set functions and I really won't use them.

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
  • Possible duplicate of [Python: Assigning "through" an iterator](https://stackoverflow.com/questions/19562356/python-assigning-through-an-iterator) – quamrana May 04 '18 at 07:45
  • 1
    You may want to read this first : https://nedbatchelder.com/text/names.html - thinking in terms of other languages never works well. And in your case, the simple obvious solution is to provide a distinct setter function. – bruno desthuilliers May 04 '18 at 08:06
  • https://stackoverflow.com/questions/8744113/python-list-by-value-not-by-reference dude I literally just said I wouldn't use set get function, – Emmanuel Lopez May 04 '18 at 20:11

0 Answers0