Predict the output
What does this print?
short, long_ = "ace", "abcde"
i = 0
for ch in long_:
if i < len(short) and ch == short[i]:
i += 1
print(i == len(short), i)Choose an answer, then open Show answer below to check it.
Show answer
Answer: A True 3
Right: a, c and e are matched in order.
The pointer only advances on a match, so it ends at the number of short stops found in order.
Why not the others?
- B False 2. e is matched at the end of the long route.
- C True 5. i counts matched short stops, not long stops.