I have a python function which returns all keys and children of a Btree:
def getAllElements(self,output=[]):
for i in self.values:
output.append(i)
if not self.children == None:
for i in self.children:
i.getAllElements(output)
return output
I am calling this function from other multiple functions like:
all_elements1 = self.getAllElements()
When I print this from multiple functions I get redundant output, like:
def f1():
all_elements1 = self.getAllElements()
print(all_elements1)
def f2():
all_elements2 = self.getAllElements()
print(all_elements2)
def f3():
all_elements3 = self.getAllElements()
print(all_elements3)
I get output say as:
1
11
111
I don't understand why this is happening. I want just 1 always.