DEV Community

Discussion on: Daily Challenge #59 - Snail Sort

Collapse
colorfusion profile image
Melvin Yeo

Solution in Python based on La blatte's wonderful implementation if anyone is interested!

def snail(arr):
    return arr[0] if len(arr) == 1 else [*arr.pop(0), *[elem.pop() for elem in arr], *arr.pop()[::-1], *[elem.pop(0) for elem in arr[::-1]]] + snail(arr) if len(arr) else []