Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Cut Sentence by OrginalS
def cut_sentence(line, length):
if length >= len(line):
return line
arr, used, res = line.split(), 0, ""
for elm in arr:
used += len(elm) + 1
if used - 1 <= length:
res += elm + " "
else:
return f"{res.rstrip()}..."
return res.rstrip()
April 17, 2020