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

Prompt: Write a string function multi_find (some_string, sub_string, [ ,start] [

ID: 3765827 • Letter: P

Question

Prompt:

Write a string function multi_find (some_string, sub_string, [ ,start] [ ,end]) where start and end are optional arguements with default values for the start and end of some_string. The start and end are interpreted as they are in slicing, that is:

a.) The program should return a list of indices of occurence of sub_string in some_string. If the substring is not found, return an empty list.

b.) Demonstrate that your string function works and that you can use it in a Boolean expression.

End Prompt

How can I solve this using Python 3?

Explanation / Answer

#! /usr/bin/env python
import sys
  
def generateCombination(inp):
if len(inp) == 1:
return [[],[inp[0]]]
  
myContrib = inp[0]
rest = generateCombination(inp[1:])
result = []
for aCombination in rest:
s = aCombination[:]
t = aCombination[:]
t.append(myContrib)
result.append(s)
result.append(t)
  
return result

if __name__ == '__main__':
inp = map(lambda x : int(x), sys.argv[1].split(" "))
result = generateCombination(inp)
for anItem in result:
print anItem