Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FOR PYTHON: Write a function findSubStrs () that takes a list of strings as a pa

ID: 640905 • Letter: F

Question

FOR PYTHON: Write a function findSubStrs() that takes a list of strings as a parameter. It prints every string in the list that is a substring of the one that precedes it (comes immediately before it in the list), one per line. If the list is empty or contains only one string, the function doesn't print anything. Note that this means that the function will never print the first item in the list since it has no predecessor in the list. The following shows several sample runs of the function:

Python 3.4.1 Shell File Edit Shell Debug Options indows Help >>> findSubStrs ([' hope,hop','hopefully, 'test', 'testing ]) hop >>> findSubStrs ([' hopefully, 'hope', hop'testing', 'test ]) hope hop test >>> findSubStrs([one ] findSubStrs ( t1) blue blu Ln: 51 Col: 4

Explanation / Answer

def findSubStrs(lst):
   if len(lst) > 1:
       for i in range(1, len(lst)):
           if lst[i].find(lst[i - 1]) != -1:
               print(lst[i])