Answer to Question #198372 in Python for Latha

Question #198372

We run the "Word mix" code , The output will be lie this


The nth word in the output should contain nth 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.


Ex: Input :: Welcome to your first problem


Output :: Wtyfp eooir luro crsb otl me em


1
Expert's answer
2021-05-25T18:01:54-0400
s = input("Enter string: ")# 'Welcome to your first problem'


w1 = s.split(' ')
w2 = [''] * len(max(w1, key=len))
for i in range(len(max(w1, key=len))):   
    for k in range(len(w1)):
        if i < len(w1[k]):
            w2[i] = w2[i] + w1[k][i]
print(' '.join(w2))
    

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