Problem 100689 · easy · Phase 01 Prerequisites & Setup

Vowels per Word

strings · lists · nested loops · conditionals

This is the Phase 1 capstone: it uses a bit of everything you have learned.

Write a function vowel_counts(sentence) that returns a list containing, for each word in sentence, the number of vowels in that word. The vowels are a e i o u, and upper-case vowels count too. Words are separated by one or more spaces.

Examples

Input:  sentence = "Hello world"
Output: [2, 1]
Explanation: "Hello" has e and o; "world" has o.
Input:  sentence = "AEIOU xyz"
Output: [5, 0]
Input:  sentence = ""
Output: []
Explanation: No words, so no counts.

Constraints

  • 0 <= len(sentence) <= 200
  • Words contain only letters; y is not a vowel here.

Goals

  • Combine split(), a loop over words and a loop over characters
  • Use the in operator to test membership in a string
  • Collect one result per input item into a list
Starting Python…