jweinst1
6/18/2015 - 11:50 PM

String Slicing Method.py

String Slicing Method.py

#for each time a certain value appears in a string, it will append the sliced
#interval of that to a list, and return the list.
#it will not attach the portion of the string before te first time
#the character appears.

def string_slicer(string, value):
	def string_indexer(string, value):
		indices, istring = [], list(string)
		for s in istring:
			if s == value:
				indices.append(istring.index(s))
				istring[istring.index(s)] ='X'
		return indices
	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