Write a program to mix the words based on their index locations
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']
Comments
Leave a comment