How to install AutoCAD 2007 | AutoCAD 2007

Опубликовано: 14 Июль 2026
на канале: Rabby Hasan
893
15

def count_word_frequency(input_string):
Split the input string into words
words = input_string.split()

Create an empty dictionary to store word frequencies
word_freq = {}

Count the frequency of each word
for word in words:
if word in word_freq:
word_freq[word] += 1
else:
word_freq[word] = 1

Create a dictionary to store frequencies as keys
and lists of words as values
freq_words = {}
for word, freq in word_freq.items():
if freq in freq_words:
freq_words[freq].append(word)
else:
freq_words[freq] = [word]

Sort the dictionary by keys
sorted_freq_words = sorted(freq_words.items())

Print the word frequencies
for freq, word_list in sorted_freq_words:
for word in word_list:
print(f"{freq}: '{word}'")

Get input string from the user
input_string = input("Enter a string: ")

Call the function to count word frequencies and print the result
count_word_frequency(input_string)