Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Popular Words by Pavellver
def popular_words(text: str, words: list) -> dict:
a = dict.fromkeys(words)
for i in words:
a[i] = text.lower().split().count(i)
return a
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(
"\nWhen I was One\nI had just begun\nWhen I was Two\nI was nearly new\n",
["i", "was", "three", "near"],
) == {"i": 4, "was": 3, "three": 0, "near": 0}
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 8, 2023
Comments: