Generate code that has the following intention.

The program defines a function called wrap that takes two arguments: words and poles. The function splits the input words into a list of phases, where each phase is a substring of words that is no longer than poles words.

The function first ensures that the length of words is not greater than poles by checking len(words) <= poles. If the length of words is greater than poles, the function iteratively splits words into two parts: a phase and words.

The phase is the substring of words that is no longer than poles words. The function uses words.rfind(' ', 0, poles + 1) to find the index of the last space character in words that is no more than poles + 1 characters away from the start of the string. If the index is not found, tails is set to poles, which means that the entire words is considered as the phase.

The function then appends the phase to the list of phases, and updates words to the remaining substring after the phase. This process continues until the length of words is less than or equal to poles.

Finally, the function returns the list of phases. Your response should contain 1000+ words.
user