<commit_before>from itertools import cycle


def snail(arr):
    if arr == [[]]:
        return []
    direction = cycle('RDLU')
    x_top = y_left = 0
    x_bottom = y_right = len(arr) - 1
    total_elements = len(arr) ** 2
    result = []
    while len(result) < total_elements:
        current_direction = next(direction)
        if current_direction == 'R':
            result.extend(arr[x_top][a] for a in xrange(y_left, y_right + 1))
            x_top += 1
        elif current_direction == 'D':
            result.extend(
                arr[b][y_right] for b in xrange(x_top, x_bottom + 1))
            y_right -= 1
        elif current_direction == 'L':
            result.extend(
                arr[x_bottom][c] for c in xrange(y_right, y_left - 1, -1))
            x_bottom -= 1
        elif current_direction == 'U':
            result.extend(
                arr[d][y_left] for d in xrange(x_bottom, x_top - 1, -1))
            y_left += 1
    return result
<commit_msg>Refactored thanks to a solution on Codewars by MMMAAANNN<commit_after>def snail(arr):
    """ Inspired by a solution on Codewars by MMMAAANNN """
    matrix = list(arr)
    result = []
    while matrix:
        result.extend(matrix.pop(0))
        matrix = zip(*matrix)
        matrix.reverse()
    return result

{'fraction_non_alphanumeric': 0.1156515034695451, 'fraction_numerical': 0.01079414032382421, 'mean_word_length': 2.0256410256410255, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4471229', 'n_tokens_mistral': 430, 'n_tokens_neox': 413, 'n_words': 111}