In this tutorial, you will learn how to find the frequency of each word in a string and display it in Command-Line using Python 3 Code.
# Python code to find frequency of each word def freq(str): # break the string into list of words str = str.split() str2 = [] # loop till string values present in list str for i in str: # checking for the duplicacy if i not in str2: # insert value in str2 str2.append(i) for i in range(0, len(str2)): # count the frequency of each word(present # in str2) in str and print print('Frequency of', str2[i], 'is :', str.count(str2[i])) def main(): str ='apple mango apple orange orange apple guava mango mango' freq(str) if __name__=="__main__": main() # call main function
We evaluated the performance of Llama 3.1 vs GPT-4 models on over 150 benchmark datasets…
The manufacturing industry is undergoing a significant transformation with the advent of Industrial IoT Solutions.…
If you're reading this, you must have heard the buzz about ChatGPT and its incredible…
How to Use ChatGPT in Cybersecurity If you're a cybersecurity geek, you've probably heard about…
Introduction In the dynamic world of cryptocurrencies, staying informed about the latest market trends is…
The Events Calendar Widgets for Elementor has become easiest solution for managing events on WordPress…