Find the first character in a string that appears exactly once.
Input
A single line: a string s of lower-case English letters.
Output
The first character that occurs exactly once, or none if every character repeats.
Find the first character in a string that appears exactly once.
A single line: a string s of lower-case English letters.
The first character that occurs exactly once, or none if every character repeats.
Example 1
leetcode
l
l is the first letter that appears only once.
Example 2
aabbcc
none
Every letter repeats, so none.
Example 3
abcabd
c
a and b repeat; c is the first singleton.
First count how many times each character appears.
Then scan the string left to right and return the first character whose count is 1.
Count character frequencies in one pass, then scan again for the first character with frequency 1.
from collections import Counter
s = input()
c = Counter(s)
print(next((ch for ch in s if c[ch] == 1), "none"))
Tell us what needs to change, who it affects and any important deadline. We will review the context and reply with useful next questions.