Skip to main content

Section 9.18 Pure Functions

The revised version of the remove_negative function that we developed in Section 9.17 is a pure function. A pure function does not produce side effects such as printing to the screen or changing its parameters. It communicates with the calling program only through parameters (which it does not modify) and a return value.

Checkpoint 9.18.1.

A word is “vowelicious” if it contains four or more vowels. (If you never heard this word before, it’s because I made it up just now for this book.) For example, “mountain” and “bookbinder” are vowelicious; “trailer” and “reading” are not.
Write a program that takes a list of words and creates a new list containing only the vowelicious words. Your program should have two pure functions:
  • count_vowels, which takes a string and returns the number of vowels it contains
  • keep_vowelicious, which takes a list of words and returns a new list containing only the words that have four or more vowels.
Hint.
The keep_vowelicious function should call the count_vowels function.