The code so un-pythonic :) This is shorter (and easier to read, imho):
argmax = lambda lst, n: max((v, i) for i, v in enumerate(lst[:n]))[1]
flip = lambda arr, n: arr[0:n][::-1] + arr[n:]
def pancakesort(data):
n = len(data)
while n:
m = argmax(data, n)
data = flip(data, m + 1)
data = flip(data, n)
n -= 1
rerturn data
print(panckakesort(data))
The code so un-pythonic :) This is shorter (and easier to read, imho):
But the idea is nice :)
This one looks interesting, the first lines are confusing but it work. The code on the article shows error in line 20. Typo with the variables.