-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnail.py
More file actions
34 lines (31 loc) · 735 Bytes
/
snail.py
File metadata and controls
34 lines (31 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
array = [[1,2,3,1,2,2],
[4,5,6,4,3,4],
[7,8,9,7,6,2],
[7,8,9,7,8,6],
[4,5,6,4,3,7],
[1,2,3,1,2,2]]
def snail(array):
if array == [[]]:
return []
final = []
while (array.count([]) != len(array)):
first_part = []
rev_second_part = []
size = len(array)
first_part.extend(array[0])
if len(array) > 1:
for i in range(1,size-1):
rev_second_part.append(array[i][0])
first_part.append(array[i][-1])
del array[i][0]
del array[i][-1]
first_part.extend(array[-1][::-1])
del array[0]
del array[-1]
final.extend(first_part)
final.extend(rev_second_part[::-1])
else:
final.append(array[0][0])
del (array[0][0])
return final
print snail(array)