Multi-String-Slicing-Method.py
#takes a string and created a slice for every time a specific value appears
#in a string. This one creats a multidict that slices independently of each value.
def set_string_indexer(string, set):
# returns all indexes for which a value in a set appears in a string, in the
#form of a multidict
indices, istring = {x:[] for x in set}, list(string)
for s in istring:
if s in set:
indices[s].append(istring.index(s))
istring[istring.index(s)] ='X'
return indices
def string_slicer(string, value):
slices, indices = [], string_indexer(string, value)
stopslice = 0
while stopslice < len(indices) - 1:
start, end = indices[stopslice], indices[stopslice+1]
slices.append(string[start:end])
stopslice += 1
return slices
def set_string_slicer(string, set):
indices = set_string_indexer(string, set)
slices = {x:string_slicer(string, x) for x in indices.keys()}
return slices