University of Arizona, Department of Computer Science

CSc 120: Words ending with

Expected Behavior

Write a function words_ending_with(wordlist, tail) that behaves as follows. The argument wordlist is a list of strings, while the argument tail is a string. words_ending_with(wordlist, tail) returns a list consisting of those strings in wordlist that end with tail. If none of the strings in wordlist end with tail, it returns the empty list.

The order of list elements in the list returned by the function should match the order of their occurrence in wordlist.

Examples

In the examples below, wordlist is the list

['evolve', 'absolve', 'crow', 'spoke', 'truck', 'lake', 'wow', 'wave']
  1. words_ending_with(wordlist, 'ow')
    Return value: ['crow', 'wow']

  2. words_ending_with(wordlist, 'lve')
    Return value: ['evolve', 'absolve']

  3. words_ending_with(wordlist, 'e')
    Return value: ['evolve', 'absolve', 'spoke', 'lake', 'wave']

  4. words_ending_with(wordlist, 'ke')
    Return value: ['spoke', 'lake']

  5. words_ending_with(wordlist, 'ing')
    Return value: []