-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsamestructureas.py
More file actions
31 lines (25 loc) · 1.04 KB
/
samestructureas.py
File metadata and controls
31 lines (25 loc) · 1.04 KB
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
def same_structure_as(original, other):
if not type(original) == type(other):
return False
if not len(original) == len(other):
return False
def get_structure(lis, struct=[]):
for i in range(len(lis)):
if type(lis[i]) == list:
struct.append(str(i) + ': yes')
get_structure(lis[i], struct)
else:
struct.append(i)
return struct
return get_structure(original, []) == get_structure(other, [])
if __name__ == '__main__':
print(same_structure_as([1, 1, 1], [2, 2, 2]))
print(same_structure_as([1, [1, 1]], [2, [2, 2]]))
print(same_structure_as([1, [1, 1]], [[2, 2], 2]))
print(same_structure_as([1, [1, 1]], [2, [2]]))
print(same_structure_as([[[], []]], [[[], []]]))
print(same_structure_as([[[], []]], [[1, 1]]))
print(same_structure_as([1, [[[1]]]], [2, [[[2]]]]))
print(same_structure_as([], 1))
print(same_structure_as([], {}))
print(same_structure_as([1, '[', ']'], ['[', ']', 1]))