The function below takes two string parameters: sentence is a string containing a series of words separated by whitespace and letter is a string containing a single lower case letter. Complete the function to return a string containing one of the words in sentence that contains letter (in either upper case or lower case). Your code should return the word with its capitalization in the original sentence. If there are multiple words in sentence that contain letter, you can return any of them. student.py

Respuesta :

Answer:

def extract_word_with_given_letter(sentence, letter):

   words = sentence.split()

   for word in words:

       if letter in word.lower():

           return word

   return ""

# Testing the function here. ignore/remove the code below if not required

print(extract_word_with_given_letter('hello HOW are you?', 'w'))

print(extract_word_with_given_letter('hello how are you?', 'w'))