DEV Community

Discussion on: Daily Challenge #180 - SMS Shortener

Collapse
 
korguy profile image
KORguy • Edited

python solution

def SMS_shortner(msg):
    while len(msg) > 160:
        try:
            lst = msg.split(" ")
            lst.append(lst.pop(-2) + lst.pop().title())
            msg = " ".join(lst)
        except IndexError:
            print("Text can not be shortened.")
    return msg