re-implemented tweet shortening algorithm in python