this is a pure python implementation of the pancake sort algorithm for doctests run following command python3 m doctest v pancakesort py or python m doctest v pancakesort py for manual testing run python pancakesort py sort array with pancake sort param arr collection containing comparable items return collection ordered in ascending order of items examples pancakesort0 5 3 2 2 0 2 2 3 5 pancakesort pancakesort2 5 45 45 5 2 find the maximum number in arr reverse from 0 to mi reverse whole list sort array with pancake sort param arr collection containing comparable items return collection ordered in ascending order of items examples pancake_sort 0 5 3 2 2 0 2 2 3 5 pancake_sort pancake_sort 2 5 45 45 5 2 find the maximum number in arr reverse from 0 to mi reverse whole list
def pancake_sort(arr):
    
    cur = len(arr)
    while cur > 1:
        
        mi = arr.index(max(arr[0:cur]))
        
        arr = arr[mi::-1] + arr[mi + 1 : len(arr)]
        
        arr = arr[cur - 1 :: -1] + arr[cur : len(arr)]
        cur -= 1
    return arr


if __name__ == "__main__":
    user_input = input("Enter numbers separated by a comma:\n").strip()
    unsorted = [int(item) for item in user_input.split(",")]
    print(pancake_sort(unsorted))