6 questions on what this module teaches. Guessing is fine: this is your starting point, not a test. Take the same check again at the end to see what you learned.
1. What does this print? t = ['.', 'z', 'o', 'e', '.']
pairs = list(zip(t, t[1:]))
print(len(pairs), pairs[-1]) 4 ['e', '.'] 4 ('.', 'z') 5 ('e', '.') 4 ('e', '.')
2. What does this print? docs = ['bob', 'abby']
uchars = sorted(set(''.join(docs)))
BOS = len(uchars)
print(uchars, BOS) ['abby', 'bob'] 2 ['a', 'b', 'o', 'y'] 5 ['b', 'o', 'a', 'y'] 4 ['a', 'b', 'o', 'y'] 4
3. What does this print? row = []
m = []
for r in range(3):
row.append(r)
m.append(row)
print(m[0]) [[0], [0, 1], [0, 1, 2]] 0 [0] [0, 1, 2]
4. What does this print? class Score:
def __init__(self, points):
self.points = points
def __add__(self, other):
return Score(self.points + other.points)
a = Score(3)
b = Score(4)
c = a + b + Score(10)
print(c.points, a.points) an error: Score objects cannot be added 7 3 17 17 17 3
5. needs = {'tea': ['water', 'kettle'], 'water': [], 'kettle': ['plug'], 'plug': []}. Which arrow is in this graph? tea → kettle kettle → tea plug → water water → kettle
6. stoi = {'a': 0, 'b': 1, 'c': 2} turns letters into ids. Which loop builds itos = {0: 'a', 1: 'b', 2: 'c'}, turning ids back into letters? (itos starts as {}.) for ch in stoi: itos[ch] = stoi[ch] itos = sorted(stoi) for ch in stoi: itos[stoi[ch]] = ch for ch in stoi: itos[ch] = ch
Answer all 6 to see your result Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy