Answer to Question #218181 in Python for Krish

Question #218181

Write a program to mix the words based on their index locations


1
Expert's answer
2021-07-22T06:19:06-0400
def mix_words (array: list, indexes: list, word: str):
  if len(array)>=len(indexes):
    if max(indexes)<len(array):
      for index in indexes:
        array[index] = word
    else:
      raise Exception()

  else:
    raise Exception()
  return array 

input:

mix_words(['ben','paul','susan','gary'], [1,3], 'bill')

output:

['ben', 'bill', 'susan', 'bill']

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS