-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_repeat_char.py
More file actions
43 lines (34 loc) · 959 Bytes
/
first_repeat_char.py
File metadata and controls
43 lines (34 loc) · 959 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
''' Write a function to find the first character in a string that repeats .
Repeating character means the character that occurs more than once in a
string.
For example,
"racecar"
1.'r'
2.'a'
3.'c'
The character that repeats first is "c" Similarly, in the string "programiz" the only character
that repeats is ʹrꞌ
Return the first repeating character from the given string s
If no repeating characters are found, return 'C'
the only character that repeats is
so it is considered as the first repeating character here.
Input: "programiz"
Output:"r"
input = "rotator"
output: 't'
Input = "ice"
output : "No repeating characters"
Input:'hello'
output :"l"
Input:'abcdefg'
Output : "No repeating characters"
'''
def first_repeating_char(s):
repeat=[]
for i in s:
if i in repeat:
return i
elif i not in repeat:
repeat.append(i)
return "No repeating characters"
print(first_repeating_char("racecar"))