Question: Python 3 ''' Purpose: Parameter(s): Return Value: ''' Write a function find_substring(string, substring) that takes in two strings, where string is some string, and substring
Python 3
'''
Purpose:
Parameter(s):
Return Value:
'''
Write a function find_substring(string, substring) that takes in two strings, where string is some string, and substring represents a string contained in string. The function must return a list of all the locations where the substring is found in string (the index of the first character of substring in string).
You are welcome to add test cases for this function to the if __name__ == '__main__' block, but this is not required.
Hints:
If the substring does not appear in string return the empty list
If a substring contains a repeating pattern it may be possible for the substring to start a second time within the first occurrence of the substring (look at the third test case below).
Examples for test case (values in bold are returned):
>>> find_substring("It was the best of times, it was the worst of times", "i")
[20, 26, 47]
Step by Step Solution
3.55 Rating (159 Votes )
There are 3 Steps involved in it
To solve this problem we can use the find method of Pythons str class This method returns the ... View full answer
Get step-by-step solutions from verified subject matter experts
