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
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…