{"id":8830,"date":"2023-11-04T11:11:45","date_gmt":"2023-11-04T05:41:45","guid":{"rendered":"https:\/\/python-programs.com\/?p=8830"},"modified":"2023-11-10T12:15:59","modified_gmt":"2023-11-10T06:45:59","slug":"python-program-to-count-the-frequency-of-words-appearing-in-a-string-using-a-dictionary","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-count-the-frequency-of-words-appearing-in-a-string-using-a-dictionary\/","title":{"rendered":"Python Program to Count the Frequency of Words Appearing in a String Using a Dictionary"},"content":{"rendered":"

Dictionaries in Python:<\/strong><\/p>\n

Dictionary is a mutable built-in Python Data Structure. It is conceptually related to List, Set, and Tuples. It is, however, indexed by keys rather than a sequence of numbers and can be thought of as associative arrays. On a high level, it consists of a key and its associated value. The Dictionary class in Python represents a hash-table implementation.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string =\"hello this is hello BTechGeeks BTechGeeks BTechGeeks this python programming python language\"<\/pre>\n

Output:<\/strong><\/p>\n

{'hello': 2, 'this': 2, 'is': 1, 'BTechGeeks': 3, 'python': 2, 'programming': 1, 'language': 1}<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

given string =\"good morning this is good this python python BTechGeeks good good python online coding platform\"<\/pre>\n

Output:<\/strong><\/p>\n

{'good': 4, 'morning': 1, 'this': 2, 'is': 1, 'python': 3, 'BTechGeeks': 1, 'online': 1, 'coding': 1, 'platform': 1}<\/pre>\n

Program to Count the Frequency of Words Appearing in a String Using a Dictionary<\/h2>\n

There are several ways to count the frequency of all words in the given string using dictionary some of them are:<\/p>\n