Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def word_counter(text):
- word_count = {}
- textwords = text.lower().split()
- for word in textwords:
- word = "".join(char for char in word if char.isalpha())
- if word.isalpha():
- if word in word_count:
- word_count[word] += 1
- else:
- word_count[word] = 1
- else:
- try:
- raise ValueError("Input must be only string!")
- except ValueError:
- print("Everything is fine.")
- return word_count
- text = input()
- dict = word_counter(text)
- for i, j in dict.items():
- print(f'{i}:{j}')
- with open('rechnik s dumi i tehniq broi', 'w') as f:
- for i, j in dict.items():
- f.write(f'{i}:{j}\n')
- setwithvalues = set(dict.values())
- print(setwithvalues)
- list_words = list(dict.keys())
- print(list_words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement