l=[0,0,0,0,0,0,0,0,0,0,0,0]
n = 11
for i in range (0,n):
l[i] = 1
print l
carryidx = 0
for i in reversed(range(0,n - 1)):
v = l[ n - 1] + l[i]
if v > 9:
while l[carryidx] > 9:
carryidx += 1
l[carryidx] += 1
else:
l[n - 1] = v
l[i] = l[i] - 1
print l
Output
[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 0, 2, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 0, 0, 3, 0, 0, 0, 0, 0, 0]
[1, 1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0]
3
solved All possible set of digits that sum==n in python list [closed]