-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathp4_9.py
More file actions
35 lines (26 loc) · 655 Bytes
/
p4_9.py
File metadata and controls
35 lines (26 loc) · 655 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
35
# BST Sequences
def rec_weave(l1, l2, atm_ans):
lol = []
if l1:
rest_of_lists = rec_weave(l1[1:], l2, atm_ans + [l1[0]])
lol.extend(rest_of_lists)
else:
return [atm_ans + l2]
if l2:
rest_of_lists_2 = rec_weave(l1, l2[1:], atm_ans + [l2[0]])
lol.extend(rest_of_lists_2)
else:
return [atm_ans + l1]
return lol
# [1,2]
# [3,4]
# Result: [1,2,3,4], [3,4,1,2], and others
def weave(l1, l2):
return rec_weave(l1, l2, [])
# l1 [1]
# l2 [2]
# [2,1 ], [1,2]
if __name__ == "__main__":
print("Result")
# print(weave([1], [2]))
print(weave([1], [3, 5, 4]))