look at first letter in list and append word for assertion


I have a list of names, such as: words=[‘cat’, dog’, ‘lion’,‘snake’, ‘fox’]

I then want to write a function that looks at the words that start with c and s and validate that through an assertion as follow:

def get_words_that_start_with(letter):


assertion( '8a' , get_words_that_start_with( 'c' ), [ 'cat' ])

assertion( '8b' , get_words_that_start_with( 's' ), [ 'snake' ])

1 Like

We don’t do homework, but we will make suggestions. Usually we would
like you to come to us with what code you’ve tried, its (failing) output
or error messages.

Checking the strings can be done using the methods the str class comes
with (all your strings are of type “str”). The str class and its methods
are documented here:


Assertions are documented here:


I notice that your get_words_that_start_with() function template only
receives the letter, not the strings to consider. Normally you would
have a second parameter containing the list of strings. That way you can
iterate over those strings looking at each in turn, probably using a

Cameron Simpson cs@cskk.id.au