How to find the first character that is repeated in a string with Python

1 Answer

0 votes
def get_first_character_repeated(s): 
    ln = len(s)
    for i in range(ln): 
        for j in range (i + 1, ln): 
            if (s[i] == s[j]): 
                return i
    return -1
 
   
s = "abcdxypcbop"
i = get_first_character_repeated(s) 
if (i == -1): 
    print("Not found") 
else: 
    print (s[i]) 
 
 
 
'''
run:
 
b
 
'''

 



answered Jan 25, 2020 by avibootz
edited Jan 25, 2020 by avibootz

Related questions

...