word_mixer Function has 1 argument: an original list of string words, containing greater than 5 words and the function returns a new list. sort the original list create a new list

Respuesta :

Question

word_mixer Function has 1 argument: an original list of string words, containing greater than 5 words and the function returns a new list.

sort the original list

create a new list

Loop while the list is longer than 5 words:

in each loop pop a word from the sorted original list and append to the new list

pop the word 5th from the end of the list and append to the new list

pop the first word in the list and append to the new list

pop the last word in the list and append to the new list

return the new list on exiting the loop

Answer:

def word_mixer Function (list):

  #new list

   new_list=[ ]

   #original list

   old_list=list

   # loop while the length of list is greater than 5.

       while len(old_list)>5:

           word_1=old_list.pop(4)         # pop fifth word from original

           new_list.append(word_1)    # append 5th word  to new list          

           

           word_2=old_list.pop()          # pop last word from original

           new_list.append(word_2)    # append last word  to new list

           

           word_3=old_list.pop(0)        # pop first word from original

           new_list.append(word_3)    # append first word  to new list return(new_list)                          # return new list

ACCESS MORE
EDU ACCESS
Universidad de Mexico