• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 1. Entering and output of data

Difficulty level:

Task«Simple text analysis»

Write a program that accepts the line of the text on the input and displays the number of entries of each word. When calculating, you should ignore the register of symbols (believe that the "word" and "word" are one and the same) and any punctuation marks.

Input format

One line containing arbitrary text.

Output format

Bring each unique word and through the colon with a gap its amount in the text. Each pair "Word: quantity" should be displayed on a new line. The order of the output of words does not matter.

Example

Input

HELLO, World! HELLO EVERYONE.

Output

HELLO: 2
world: 1
EVERYONE: 1

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Developer’s solution
import re
from collections import Counter
# Считываем входную строку текста
text = input()
# Приводим весь текст к нижнему регистру
lower_text = text.lower()
# Используем регулярное выражение для поиска всех "слов"
# \w+ находит любую последовательность букв (включая кириллицу), цифр и знака подчеркивания
words = re.findall(r'\w+', lower_text)
# Используем Counter для автоматического подсчета вхождений каждого слова
word_counts = Counter(words)
# Сортируем слова по алфавиту и выводим результат
# word_counts.items() возвращает пары (слово, количество)
for word, count in word_counts.items():
    print(f"{word}: {count}")

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

Помощник ИИ

Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!