In this article, we will discuss the concept of the Python code: Find the frequency of each character in the string
In this post, we are going to learn how to find the frequency of the each character of the given string in Python programming language
The program allows the user to enter a String and then it finds the frequency of the each characters in the given string
program 1
string=input("Enter the string ") freq=[None]*len(string) for i in range(0,len(string)): freq[i]=1 for j in range(i+1,len(string)): if(string[i]==string[j]): freq[i]=freq[i]+1 string=string[:j]+'0'+string[j+1:]; print("Character and their frequency"); for i in range(0,len(freq)): if(string[i]!=' ' and string[i]!='0'): print(string[i]+"="+str(freq[i]))
When the above code is executed, it produces the following result
Enter the string python Character and their frequency p=1 y=1 t=1 h=1 o=1 n=1
The program allows the user to enter a String and then it finds the frequency of the each character in the given string
Program 2
string=input("Enter the string: ") str1=list(string) strlist=[] for j in str1: if j not in strlist: strlist.append(j) count=0 for i in range(len(str1)): if j==str1[i]: count+=1 print("{},{}".format(j,count))
When the above code is executed, it produces the following result
Enter the string: mypython m,1 y,2 p,1 t,1 h,1 o,1 n,1
Suggested for you
if statements in Python
Similar post
C++ program to count the total number of characters in the given string
C program to count the total number of characters in the given string
Python program to count the total number of characters in the given string
Java program to count the frequebcy of a character of a string
C program to count the frequebcy of a character of a string
Python program to count the frequebcy of a character of a string
C++ program to count the frequebcy of a character of a string
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…