# Lab 08
# Q1: Insert
if index == 0:
link.rest = Link(link.first,link.rest)
link.first = value
elif link.rest is Link.empty:
raise IndexError
else:
insert(link.rest, value, index - 1)
1
2
3
4
5
6
7
2
3
4
5
6
7
# Q2: Determining Efficiency
# Q3: Subsequences
def insert_into_all(item, nested_list):
return [[item] + rest for rest in nested_list]
def subseqs(s):
if not s:
return [[]]
else:
with_in = insert_into_all(s[0],subseqs(s[1:]))
with_out = subseqs(s[1:])
return with_in + with_out
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
← Lab 07 Homework 6 →