uinput = 'sample line of text text'
#print(len(uinput))
uinputlist = list(uinput) #makes the text a mutable list
indices = [i for i, x in enumerate(uinputlist) if x == ' '] #finds the index for each space
listindices = list(indices) #makes indices a mutable list
#print(listindices) #showing what indices a space is at.
uinputlistnew = uinputlist #initialize
x = ' ' #x is the variable for spaces
def spacefinder(cutoff): #find spaces,
for i in listindices:
uinputlistcutoff = uinputlist[cutoff-2:cutoff+2]
# print(uinputlistcutoff)
if x in uinputlistcutoff:
uinputlistnew = uinputlist[0:i]
if len(uinputlistnew) >=cutoff-2:
# print(uinputlistnew)
cutoffoutputlist = ''.join(uinputlistnew).strip(' ')
cutoffoutput = list(cutoffoutputlist)
return cutoffoutput
# print('test')
elif len(uinputlist) >= cutoff:
uinputlistnew = uinputlist[0:cutoff]
cutoffoutput = uinputlistnew
return cutoffoutput
else:
cutoffoutput = 'wrong'
return cutoffoutput
def ellipses():
cutoffinput = None
print('choose a cutoff value')
try:
cutoffinput = int(input())
except ValueError:
print('Sorry Try Agian')
ellipses()
return
finally:
print('Cutoff is an int')
cutoffoutput = 'hm'
if len(uinput) >= cutoffinput:
newoutput = spacefinder(cutoffinput)
print(''.join(newoutput)+'...')
else:
print(uinput)
ellipses()