while loop looks for a key whose value is 0. The loop has an else block, and the program then uses the counter as an index.
d = {"a": 3, "b": 2, "c": 5}
keys = list(d)
i = 0
while i < len(keys):
if d[keys[i]] == 0:
break
i += 1
else:
i = -1
print(i, keys[i])
What does the program print?Log in to join the discussion.
Loading…