Okay so first, I may have misinterpreted what you were looking for but if you are looking for a character that does not immediately repeat ('aa') then this should work for you.
You are iterating over the entire array one and a portion. I did it like this:
def first_non_repeat(s):
if len(s) == 1:
return s
for i in range(len(s)):
if (i == 0 and s[i+1] != s[i]) or (i<len(s)-1 and s[i-1] != s[i] and s[i] != s[i+1]) or (i == len(s)-1 and s[i-1] != s[i]):
return s[i] # or return i
return None
It loops over the array but only as much as it needs to in order to get the first non-repeated letter. The if statement checks if the character behind and in front of the current index don't match the one at the current index, if so it returns that letter. Note, you could also have it return the index which would potentially be more useful.
If you put in
"HHHHELLLO WORLD!"
the output from the function is 'E' or if you changed it to return index value it will return 4.
printwithreturn...your code still remains buggy tho