def snail(nums: list) -> list:
new_sort_list = []
while True:
new_sort_list += nums[0]
del nums[0]
if len(nums) == 0:
break
new_sort_list += [ns[len(ns) - 1] for ns in nums]
for ns in nums:
del ns[len(ns) - 1]
new_sort_list += nums[len(nums) - 1][::-1]
del nums[len(nums) - 1]
if len(nums) == 0:
break
new_sort_list += [ns[0] for ns in nums][::-1]
for ns in nums:
del ns[0]
if len(nums) == 0:
break
return new_sort_list
assert snail([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [1, 2, 3, 6, 9, 8, 7, 4, 5]
assert snail([[1, 2, 3], [8, 9, 4], [7, 6, 5]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9]
assert snail([[1, 2, 3, 1], [4, 5, 6, 4], [7, 8, 9, 7], [7, 8, 9, 7]]) == [1, 2, 3, 1, 4, 7, 7, 9, 8, 7, 7, 4, 5, 6, 9,
8]