DESCRIPTION:
Write a function named first_non_repeating_letter that takes a string input, and returns the first character that is not repeated anywhere in the string.
For example, if given the input 'stress', the function should return 't', since the letter t only occurs once in the string, and occurs first in the string.
As an added challenge, upper- and lowercase letters are considered the same character, but the function should return the correct case for the initial letter. For example, the input 'sTreSS' should return 'T'.
If a string contains all repeating characters, it should return an empty string ("") or None -- see sample tests.
def first_non_repeating_letter(string):
stringL=string.lower()
place=0
for i in stringL:
if stringL.count(i)==1:
return string[place]
place+=1
return ''
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
WeIrD StRiNg CaSe (0) | 2022.10.11 |
---|---|
Extract the domain name from a URL (0) | 2022.10.11 |
Weight for weight (0) | 2022.10.11 |
Detect Pangram (0) | 2022.10.07 |
Bouncing Balls (0) | 2022.10.07 |