Python List Values being assigned to each other -


i'm having problem writing following code:

d = [         [0,3,8,999,-4],         [999,0,999,1,7],         [999,4,0,999,999],         [2,999,-5,0,999],         [999,999,999,6,0]     ]  def floydwarshall (w):     matrices = [w[:]]     pred = [w[:]]      print (matrices pred)     print (pred matrices)     print (pred w)     print (matrices w)      in range(0,len(pred[0])):         j in range(len(pred[0][i])):              if pred[0][i][j] != 999 , pred[0][i][j] != 0:                 pred[0][i][j] = +1             else:                 pred[0][i][j] = false       return (matrices,pred) floydwarshall(d) 

the values being returned exact same matrices, why this? print statement not pointers same spot in memory, correct?

you making shallow copy of nested lists, mutating them still affect both matrices. might want use copy.deepcopy


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -