Use enumerate function, for loop and if statement to find the first repeated character in a given string.
Python program to find the first repeated character in a given string Examples
Simple example code finds the character which occurs more than once. If there is no repeating character “None“.
def rep_char(str1): s = str1.lower() for index, c in enumerate(s): if s[:index + 1].count(c) > 1: return c return "None" print(rep_char("Python")) print(rep_char("EyeHunts"))
Do comment if you have any doubts and suggestions on this Python char program.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.