- Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathfirst_unique_letter.py
28 lines (19 loc) · 701 Bytes
/
first_unique_letter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Problem: Given a string, find the first non-repeating
# character in it. For example, if the input string is
# “GeeksforGeeks”, then output should be ‘f’ and if input
# string is “GeeksQuiz”, then output should be ‘G’.
importstring
letters=string.ascii_lowercase
CHARACTER_HASH=dict(zip(letters, [0] *len(letters)))
defmapLettersToHash(text_a):
forcharintext_a:
ifcharinCHARACTER_HASH.keys():
CHARACTER_HASH[char] +=1
defgetFirstUniqueLetter(text_a):
forcharintext_a:
ifCHARACTER_HASH[char] ==1:
returnchar
text_1="geeksquiz"
mapLettersToHash(text_1)
result=getFirstUniqueLetter(text_1)
print(result)