DEV Community

Discussion on: PANCAKE SORTING

Collapse
 
mapio profile image
Massimo Santini • Edited

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))
Enter fullscreen mode Exit fullscreen mode

But the idea is nice :)

Collapse
 
gerbosan profile image
Carlos A.

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.