Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Cut Sentence by heinrich.rhing
def pt(i):
print(i)
return i
def cut_sentence(line: str, length: int) -> str:
return pt(' '.join([j if j == line.split()[i] else '' for i,j in enumerate(line[:length].split())]).rstrip() + ('...' if len(line) > length else ''))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert cut_sentence("Hi my name is Alex", 4) == "Hi...", "First"
assert cut_sentence("Hi my name is Alex", 8) == "Hi my...", "Second"
assert cut_sentence("Hi my name is Alex", 18) == "Hi my name is Alex", "Third"
assert cut_sentence("Hi my name is Alex", 20) == "Hi my name is Alex", "Fourth"
print('Done! Do you like it? Go Check it!')
May 4, 2022