A prefix is the beginning letter of a word or group of words.
Example: The word “unhappy” consists of the prefix “un."
Given a query, string s
, and a list of all possible words, return all words that have s
as a prefix.
def prefix_words(prefix, word):if word.startswith(prefix):print("Starts with {}").format(prefix)prefix="un"word="unhappy"prefix_words(prefix,word)
A suffix is a letter or group of letters added to the end of a word.
Example: Suffix ‘-ly’ is added to ‘quick’ to form ‘quickly’.
Given a query, string s
, and a list of all possible words,
return all words that have s
as a suffix.
def suffix_words(suffix, word):if word.endswith(suffix):print("Ends with {}").format(suffix)suffix="ly"word="quickly"suffix_words(suffix, word)