Python program to find all non repeating characters in the string

Python program to find all non repeating characters in the string

In this tutorial, we will learn writing the python program to print all characters of the string which are not repeating. We can say the character are available only one time in string.

Problem Statement

Take any string as an input from the user and check if any character in the string is repeating or not. if it is not repeating then print that character as output.

For example:

Case1: If the user inputs the string ‘pythonprogramming’

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

Case2: If the user inputs the string ‘quescoll’

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

Our logic to find all non repeating characters in the string

  • Our program will take a string as an input from the user.
  • Iterate the character of the input string to check if the character is repeating or not, to achieve this we use the concept of ‘nested loop’.
  • The output is in the form of a string, where all the non-repeating characters are concatenated together using concatenation methods.

Algorithm to find all non repeating characters in the string

Step1: Start
Step2: Take a string as an input from the user
Step3: Create an empty string result=”” to store non-repeating characters in the string.
Step4: iterate through each character of the string
Step5: Declare a variable count=0 to count appearance of each character of the string
Step6: for j in string:
if i==j:
increment count to 1
if count is greater than one:
break the current iteration of nested loop
if count is equal to 1:
concatenate the character with the empty string, result
Step7: print result as the output of our program
Step8: Stop

Python code to find all non repeating characters in the string

Output:

Explanation:

For the input string ‘aabbcdeeffgh’, as the characters ‘a’, ‘b’, ‘e’, and ‘f’ are repeating but ‘c’, ‘d’, ‘g’ and ‘h’ are not repeating so the generated output should be ‘cdgf’.