Shortening words within a string The function receives a string containing a sentence. Its goal is to shorten every word in it to a length of 4 characters until the string is shorter than 38 characters and return.  

The 38 characters max length is mandatory and must be reached with the least amount of deletion possible.

Here is what I've done:

# reduces each word to a lenght of 4
def shorten_words(string):
    i = 0
    j = 0
    while(len(string) &gt; 38 and i &lt; len(string)):
         array = list(string)
         if(array[i] != ' ' and array[i] != '-'):
             j += 1
         else:
             j = 0
         if(j &gt; 4):
             array[i] = ''
             i -= 1
         i += 1
         string = ''.join(array)
    return(string)


I feel like the list/join method is inefficient and would like to know how I could improve this function
Some suggestions:


Naming is really important. string, array, i and j are not descriptive. After reading the entire function I think they could be renamed sentence, words, string_index and word_length.
There's no point in adding empty strings to the array - they aren't printed anyway.
What is the significance of 38? If it's not significant it should be removed, if it is it should be named something like max_result_length.
In Python return is a simple statement, which means its argument should not be put in parentheses.