The reason is you are appending the reference of the current
list to master. So, every time you change current
the previously appended lists also change.
Use this link for visualization:click here

>>>def recur(count,current):
count = count + 1
if (count == 5):
return
current.append(1)
master.append(current)
recur(count,current)
>>> master=[]
>>> recur(0,[])
>>> master
[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]
>>> for i in master:
id(i)
2485591104264
2485591104264
2485591104264
2485591104264
>>>
Method 1
You can try this. There is no need to keep track of the current
list you are appending to master
.
def recur(count):
count+=1
if count==5:
return
curr=[1]*count
#print(curr)
master.append(curr)
recur(count)
master=[]
recur(0)
print(master)
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
Method 2
If you are keen on using current
then try this.
Visualization for this code click here.

def recur(count,curr):
count+=1
if count==5:
return
curr.append(1)
master.append(curr)
recur(count,curr[:])
master=[]
recur(0,[])
print(master)
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
Method 3
Or you can try this.
def recur(count,curr):
count+=1
if count==5:
return
curr.append(1)
master.append(curr[:])
recur(count,curr)
master=[]
recur(0,[])
print(master)
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
Method 4
If you want to return [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
then try this.
def recur(count,curr):
count+=1
if count==5:
return []
curr.append(1)
return [curr]+recur(count,curr[:])
master=recur(0,[])
print(master)
another_master=recur(0,[])
print(another_master)
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]
[[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]