Program to get the duplicate characters from the string

In this python function program, we will create a function to get the duplicate characters from the string.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function dupli.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. string to the function.
  4. Create an empty list.
  5. Use a for loop to iterate over characters from the string.
  6. Check whether the character appears in the string more than once using count().
  7. If yes then add it to the empty list.
  8. Create a set of that list using set().
  9. Print the output.
  10. Pass the string to the function while calling the function.
				
					def dupli(string):
    list1 = []
    for char in string:
        if string.count(char) > 1:
            list1.append(char)
    print(set(list1))
dupli('Programming')
				
			

Output :

				
					{'g', 'm', 'r'}
				
			

Related Articles

get unique values from the given list.

get the square of all values in the given dictionary.

Leave a Comment