Answer to Question #208211 in Python for Sudheer

Question #208211

Given a sentence, write a program to mix the words based on their index locations. The first word in the output should contain the first letter of each word in the given sentence and the second word should contain the second letter of each word in the given sentence and so on.


Note: The nth word in the output should contain th letter of each word in the given sentence. The letters of the output word should be in same order as the words in the given sentence. If a word in the given sentence doesn't have n-letters, you can skip it while considering the letters of the n-th word.


Input


The input will be a single line containing a string.


The output should be a single line containing the words by mixing based on their index locations.


1
Expert's answer
2021-06-18T02:54:44-0400
in_str = input()
words_list = in_str.split()
new_words_list = []
for i in range(len(words_list)):
	tmp = ''
	for el in words_list:
		if len(el) > i:
			tmp += el[i]
	new_words_list.append(tmp)
out_str = ' '.join(new_words_list)
print(out_str)

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