Here's the solution:
def first_unique_char(s):
# Count occurrences
counts = {}
for char in s:
counts[char] = counts.get(char, 0) + 1
# Find first with count 1
for char in s:
if counts[char] == 1:
return char
return "None"
The first loop builds the frequency count. The second loop finds the first character with count exactly .
Time: for two passes through the string. Space: where is unique characters.