Editor

Test a Word Counter

Write the tests · Intermediate · about 12 min

count_words(text) returns a dictionary of how many times each word appears in text. Words are separated by spaces and counted in lowercase. The marks . , ! and ? are removed from the start and end of each word, and a mark standing on its own is not a word.

Write test_ functions with assert that pass on a correct version and fail on broken ones.

Examples

count_words("Hi, hi there!")    # {"hi": 2, "there": 1}
count_words("")                 # {}
def test_two_words():
assert count_words("hi there") == {"hi": 1, "there": 1}
The solution opens after your first Check.