Python Program to Find Lowest Frequency (Least Occurring) Character in String


This Python program finds least occurring character in a given string by user.


Python Source Code: Lowest Frequency Character


# Finding least occuring character

# Get string from user
string = input("Enter some text: ")

# Set frequency as empty dictionary
frequency_dict = {}

for character in string:
    if character in frequency_dict:
        frequency_dict[character] += 1
    else:
        frequency_dict[character] = 1

least_occurring = min(frequency_dict, key=frequency_dict.get)

# Displaying result
print("\nLeast occuring character is: ", least_occurring)
print("It is repeated %d time(s)" %(frequency_dict[least_occurring]))

Output

Enter some text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla urna purus, ultrices vitae mi quis, tristique sagittis nulla.

Least occuring character is:  L
It is repeated 1 time(s)