Checkpoint 10.3.1.
What is printed by the following statements?
alist = [ [4, [True, False], 6, 8], [888, 999] ]
for a in alist:
for b in range(1, len(a)):
if type(a[b]) == type(a[b-1]):
print(a[b], end=" ")
- 8 999
- Yes, you are correct.
- 4 6 8 888 999
- You are correct that the code will treat the list with boolean value differently, but you are missing other aspects. Look again at the bounds of the inner loop.
- 4 True False 6 8 888 999
- This would be the output for a full traversal of the data. However, this code cannot fully traverse the data since it has three levels of nesting and the code only reaches two levels.
- 4 [True, False] 6 8 888 999
- This would be the correct output if the code traversed two levels of nesting and printed everything. However, the if statement is also doing something here.