-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep_reverse.py
More file actions
33 lines (27 loc) · 809 Bytes
/
deep_reverse.py
File metadata and controls
33 lines (27 loc) · 809 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
def reverse(l):
out = list()
if len(l) == 0:
return list()
for index in range(len(l),0,-1 ):
if isinstance(l[index-1], list):
to_append = reverse(l[index-1])
else:
to_append = l[index-1]
out.append(to_append)
return out
def test_function(test_case):
arr = test_case[0]
solution = test_case[1]
output = reverse(arr)
if output == solution:
print("Pass")
else:
print("False")
test_case = [[1,2,3], [3,2,1]]
test_function(test_case)
test_case = [[1, 2, [3, 4, 5], 4, 5], [5, 4, [5, 4, 3], 2, 1]]
test_function(test_case)
test_case = [[1, [2, 3, [4, [5, 6]]]], [[[[6, 5], 4], 3, 2], 1]]
test_function(test_case)
test_case = [ [1, [2,3], 4, [5,6]], [ [6,5], 4, [3, 2], 1]]
test_function(test_case)