Question: Please write the following program in Python 3. Please also comment liberaly. # Look up methods on the str object to get a list of
Please write the following program in Python 3. Please also comment liberaly.
# Look up methods on the str object to get a list of words from the sentence # Then use a list compprehension to get the final list to return. # I'm using multi-line strings for the things to test in the REPL, # to make it easier to copy/paste """ Test in the REPL: >>> from HW3 import words_containing >>> sentence = "Anyone who has never made a mistake has never tried anything new" >>> words_containing(sentence, 'a') # Should return: ['Anyone', 'has', 'made', 'a', 'mistake', 'has', 'anything'] >>> words_containing(sentence, 'x') # Should return: [] """ def words_containing(sentence, letter): """ Given a sentence, returns list of words that contain the letter. Letter given is lowercase. Sentence can be mixed case, and the case should be ignored for searching. """ # Use exception handling for this one. # What happens when you try to get the len of something that has no len? """ Test in the REPL: >>> from HW3 import len_test >>> my_dict = {'a': 23, 'b': 8} >>> print(len_test(my_dict)) # should return: 2 >>> print(len_test(7)) # should return: -1 >>> print(len_test("")) # should return: 0 """ def len_test(obj): """Return length of object or -1 if object has no length."""
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
