In this section of python programming, our task is to find the character having minimum occurrence in the given string.
from collections import Counter input_str = input("Enter the string:") # Using Counter() + min() output = Counter(input_str) # Find min output = min(output, key = output.get) print("The least frequent character is : "+str(output))
In the above python code, we have used Counter() on the input string. The Counter() function makes the key, value pair of the characters in the input string. To find the minimum frequency character we have used min() function. And the output is printed on the screen.
Form the output above we can see that the characters t, I, n and s are also having least frequency but only character e is printed. We can conclude that the character occurring first is printed only among all the least frequent character.