My current solution is for x=3
a = "first one is"
b = "the second forever"
def fun(input):
if input.split()[-1] < 3:
return ' '.join( input.split()[0:-1])
else:
return input
fun(a)
"first one"
fun(b)
"The second forever"
Is there something more computationally efficient?