Tutorials

Python 3 Code to Find Frequency of Each Word in String

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.

main.py

# 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
Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

ChatGPT Atlas vs Google Chrome: Which Browser Should You Choose in 2025?

Google Chrome has dominated web browsing for over a decade with 71.77% global market share.…

October 25, 2025

Is Perplexity Comet Browser Worth It? The Honest 2025 Review

Perplexity just made its AI-powered browser, Comet, completely free for everyone on October 2, 2025.…

October 25, 2025

Is ChatGPT Atlas Worth It? A Real Look at OpenAI’s New Browser

You've probably heard about ChatGPT Atlas, OpenAI's new AI-powered browser that launched on October 21,…

October 25, 2025

Perplexity Comet Browser Alternatives: 7 Best AI Browsers in 2025

Perplexity Comet became free for everyone on October 2, 2025, bringing research-focused AI browsing to…

October 25, 2025

ChatGPT Atlas Alternatives: 7 Best AI Browsers in 2025

ChatGPT Atlas launched on October 21, 2025, but it's only available on macOS. If you're…

October 25, 2025

ChatGPT Atlas vs Comet Browser: Best AI Browser in 2025?

Two AI browsers just entered the ring in October 2025, and they're both fighting for…

October 25, 2025