def popular_words(text: str, words: list) -> dict:
lower_text = text.lower()
replace_text = lower_text.replace('\n',' ')
list_text = replace_text.split()
length = len(words)
values = []
for i in range(length):
values.append(0)
words_dict = dict(zip(words, values))
for text in list_text:
for word in words:
if text == word:
words_dict[word] = words_dict[word] + 1
return words_dict
if __name__ == '__main__':
print("Example:")
print(popular_words('''
When I was One
I had just begun
When I was Two
I was nearly new
''', ['i', 'was', 'three', 'near']))
assert popular_words('''
When I was One
I had just begun
When I was Two
I was nearly new
''', ['i', 'was', 'three', 'near']) == {
'i': 4,
'was': 3,
'three': 0,
'near': 0
}
print("Coding complete? Click 'Check' to earn cool rewards!")