I have an unexpected result where values of self.path and self.path_temp are different and the only way they are different is that one is updated by a string and another by a list all passed through function trav as arguments. Are lists somehow persistent in memory in python? A correct or detailed explanation would be appreciated!
PS: The correct one is self.path which is updated with the string.
def binaryTreePaths(self, root: TreeNode) -> List[str]:
self.path = []
temp = []
self.path_temp = []
def trav(root,path,temp):
if root:
path += str(root.val)
temp.append(root.val)
if root.right == None and root.left==None:
self.path.append('->'.join(path))
self.path_temp.append('->'.join(temp))
trav(root.left,path,temp)
trav(root.right,path,temp)
trav(root,'',temp)
print(self.path)
print(self.path_temp)
ls???