Last active
January 3, 2019 12:20
-
-
Save zahash/1254adfe783a1807422f1d045e5c6a49 to your computer and use it in GitHub Desktop.
function to find the non repeating character in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@time_it | |
def dict_method(st): | |
''' | |
This function will return the non-repeating | |
characters in a string | |
Args: | |
st: the input string | |
Return: | |
unique: a list of characters that don't | |
repeat in the string | |
''' | |
d = {} | |
for letter in st: | |
if letter not in d : | |
d[letter] = 1 | |
else: | |
d[letter] += 1 | |
unique = [k for k,v in d.items() if v==1] | |
return unique |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment