Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
9-liner: Cut by split & go on each stack solution in Clear category for Cut Sentence by Stensen
def cut_sentence(t, l):
if len(t) <= l: return t
stack = t.split()
answer = f if len(f:=stack.pop(0)) < l else ''
while stack:
_stack = ' ' + stack.pop(0)
if len(answer + _stack) > l: break
answer += _stack
return answer + '...'
Nov. 3, 2020
Comments: