Python program to find non repeating characters in a string

Find Non Repeating Characters

The string is a combination of characters when 2 or more characters join together it forms string whether the formation gives a meaningful or meaningless output. In python programming, we treat a single character also as a string because there is no datatype as a character in python. In this python program, we will find unique elements or non repeating elements of the string.

Find Non Repeating Characters in python

Algorithm

  • Step 1:- store the string in a varaible lets say String.
  • Step 2:- lets it be “prepinsta”.
  • Step 3:- Start iterating through string.
  • Step 4:- Initialize count variable.
  • Step 5:- Again start iterating through same string.
  • Step 6:- Increment count variable as character is found in string.
  • Step 7:- If count is more then 2 break the loop.
  • Step 8:- If count is 1 print the character.
  • Step 9:- End.

Python Code:- Find Non Repeating Characters

#take user input
String = "prepinsta"
for i in String:
    #initialize a count variable
    count = 0
    for j in String:
        #check for repeated characters
        if i == j:
            count+=1
        #if character is found more than 1 time
        #brerak the loop
        if count > 1:
            break
    #print for nonrepeating characters
    if count == 1:
        print(i,end = " ")

Output

r e i n s t a

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

26 comments on “Python program to find non repeating characters in a string”


  • dereddymaheswarareddy

    n = str(input())
    dict1 = {}
    for i in n:
    if i in dict1:
    dict1[i] += 1
    else:
    dict1[i] = 1
    string = “”
    for i in dict1:
    if dict1[i]==1:
    string += i
    else:
    continue
    print(dict1)
    print(string)


  • yugander9010

    String = “prepinsta”
    String=String.lower()
    dic=dict()
    for i in String:
    if i in dic:
    dic[i]+=1
    else:
    dic[i]=1
    print(”.join(key for key,value in dic.items() if value==1))


  • JEGAN

    def non_repeat_chr(str1):
    l =””
    for i in str1:
    if str1.count(i)==1:
    l+= i
    print(f” non-repeating char : {“,”.join(l)}”)

    str1 =input(“enter a string: “)
    non_repeat_chr(str1)


  • Yash

    String = “prepinsta”
    for i in String:
    if String.count(i)==1:
    print(i ,end=’ ‘)


  • Divya

    string = “prepinsta”

    for i in string:
    frequency = string.count(i)
    if(frequency==1):
    print(str(i),end=”,”)


  • Mohit

    #using set concept
    a=input()
    b=set(a)
    for i in b:
    if(a.count(i)<2):
    print(i,end=" ")
    else:
    pass