Hi
How can I stop a loop, this function sort my list as I wish but I want to stop it when it done the task.
I have a list x = [4,4,2] and during 15 attempt I want to sort it like that x = [1,2,3,4], if the function sort it after 8 attempt then I want to stop my loop .
I was wondering if anyone in the community could
help.
thanks
def kopi(x):
y = []
b = 0
for num in x:
new_num = num - 1
if new_num < 0:
del new_num
else:
y.append(new_num)
b+=1
y.append (b)
print b
print "new list inside function", y
return y
## 15 iterations
if __name__ == "__main__":
x=[4,4,2]
y = []
print "the beginning list is", x
for k in range(0, 15):
x=kopi(x)