In this program, we will take a string as input and find duplicate characters in a string
Steps to solve the program
- Take a string as input and create an empty list.
- Use for loop to iterate over every character of the string.
- Count the occurrences of each character in the string using count().
- If count > 1 then add that character to the empty list.
- Convert that list to a set.
- Print output
#Input string
string = "hello world"
list1 = []
for char in string:
if string.count(char) > 1:
list1.append(char)
#Printing output
print(set(list1))
Output :
{'o', 'l'}