所以我有一个4维数组,一个非常简单的函数来帮助从所述数组中获取元素。
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]]]
其中title将分别为'Aa1:2'
唯一的问题是当我尝试使用该功能进行分配时,
GrabAPeice('Bb2:2')='Q'
它不允许我分配值。
是否可以让函数在python中向另一个对象返回引用或别名?
我知道get和set函数,我真的不会使用它们。