I am solving a problem: Given a string s consisting of small English letters, find and return the first instance of a non-repeating character in it. If there is no such character, return '_'.
For example: s = "abacabad", the output should be firstNotRepeatingCharacter(s) = 'c'.
I wrote a simple code, it got through all the test, but when I submit it, it reports error, anyone know what's wrong with my code? Thank you!
def firstNotRepeatingCharacter(s):
for i in list(s):
if list(s).count(i) == 1:
return i
return '_'