Predict the output
What does this print?
from collections import Counter
s = "abacabad"
c = Counter(s)
print(next((i for i, ch in enumerate(s)
if c[ch] == 1), -1))Choose an answer, then open Show answer below to check it.
Show answer
Answer: A 3
Right: 'c' at index 3 is the first letter with a count of 1.
Counts are a: 4, b: 2, c: 1, d: 1; the scan over the string meets 'c' first.
Why not the others?
- B 7. 'd' also appears once, but later than 'c'.
- C 1. 'b' appears twice, at indexes 1 and 5.