Predict the output
Using the list form above, what does this print?
level = [8, 3, 10, 1, 6, None, 14]
i = level.index(10)
kids = [level[j] for j in (2 * i + 1, 2 * i + 2) if j < len(level)]
print(i, kids)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 2 [None, 14]
Right: 10 sits at position 2, so its children are at 5 and 6.
Children of position i are at 2i + 1 and 2i + 2, and None marks the missing left child of 10.
Why not the others?
- B 2 [1, 6]. Positions 3 and 4 hold the children of 3, at position 1.
- C 1 [None, 14]. list.index finds 10 at position 2, not 1.