In this program, we will take a string as input and find the first repeated character in a string and its index.
Steps to solve the program
- Take a string as input.
- Use for loop with range() function to find the first repeated character.
- Find the index of that character using Index().
- After finding the first character break the loop.
- Print the output.
#Input string
str1 = "sqatools"
for i in range(len(str1)):
for j in range(i+1,len(str1)):
if str1[i] == str1[j]:
print(f"({str1[i]},{str1.index(str1[i])})")
break
Output :
(s,0)