← Back to challenges

Counting Adverbs

PythonHardstringsregexloops

Instructions

Create a function that counts the number of adverbs in a sentence. An adverb is a word that ends with ly.

Examples

count_adverbs("She ran hurriedly towards the stadium.") ➞ 1

count_adverbs("She ate the lasagna heartily and noisily.") ➞ 2

count_adverbs("He hates potatoes.") ➞ 0

count_adverbs("He was happily, crazily, foolishly over the moon.") ➞ 3

Notes

  • Do NOT count words where the ly is in the beginning or the middle (e.g. Lysol, Illya).
  • For the purpose of this exercise, ignore the nuances of the English language (some adjectives also end in ly).
python3
Loading editor…
⌘ ↵ to run
Walks through the solution with reasoning and edge cases.