Python 3 ''' Purpose: Parameter(s): Return Value: ''' Write a function find_substring(string, substring) that takes in two
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 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]
Physics
ISBN: 978-0077339685
2nd edition
Authors: Alan Giambattista, Betty Richardson, Robert Richardson