This is the code for sorting a list without any method.
I had entered a print
statement in the for
loop to print the values of a
and l
.
l,a=(input("enter terms separate with ','\n")).split(','),"5"
def so(m,n,b=0):
try: return (so(m,n,b+1) if(m[b]==n[b]) else [m,n] if(ord(m[b])<ord(n[b])) else [n,m])
except: return [m,n] if(b==len(m)) else [n,m]
while(a!=l):
print(a," is assigned ",l)
a=l
for i in range((len(l)-1)):
l[i],l[i+1]=so(l[i],l[i+1])[0],so(l[i],l[i+1])[1]
print(l,i,a)
I accept that I have written a=l
in the while
loop, but the while
loop is executed only once. I knew it by inserting a print
statement inside the while
loop.
After every step in the for
loop, a
has the same value as l
which is not defined anywhere.
Also, I didn't assign a
or l
to any value in the function.