Python program to remove duplicates from string(no order intact)

Python program to remove duplicates from string(no order intact)

In this tutorial, we will learn writing python program to remove the duplicate characters from the given string.

Problem Statement

We have to take a string as an input from the user to check for duplicate characters. If there is any duplicity of characters found in string then remove it.

For example:

Case1: If the user inputs the string ‘programmingLanguage’

Then the output should be ‘ogumapenirL’, where there is no character that is repeating.

Case2: If the user inputs the string ‘LearningIsFun’

Then the output should be ‘LergisIauFn’, where there is no character that is repeating.

Our logic to remove duplicates from string

  • Firstly, take two strings as inputs from the user.
  • Then, we make all characters stored in a set, which removes the duplicates.
  • Use string concatenation methods to join the characters in the set together
  • And finally, return the concatenated string as an output of our program.

Algorithm to remove duplicates from string

Step1:  Start

Step2:   Take string as input from the user.

Step3: print  ” “.join(set(str1))

Step4: Stop

Python code to remove duplicates from string

Output 1:

python program to remove duplicates from string

Explanation:

Here, the user gives input as ‘quesquecoll’, so first, the character of the string gets converted into elements of the set, so the duplicates will get removed.

After that on join operation, the elements of the set get concatenated and return the output ‘csQueqelo’.

Output 2:

remove duplicates from string python

Explanation:

Here, the user gives input as ‘ppythonIsFFunn’, so first, the character of the string gets converted into elements of the set, so the duplicates will get removed.

After that on join operation, the elements of the set get concatenated and return the output ‘nytFhIpuos’.