Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
find space position to cut using str.rindex(), then cut inside try... except block solution in Clear category for Cut Sentence by ann3leo
def cut_sentence(line, length):
if len(line) <= length:
return line
try:
cut_space = line.rindex(' ', 0, length+1)
return line[:cut_space] + '...'
except ValueError:
return '...'
Nov. 7, 2020
Comments: