Answer to Question #195045 in Python for Pavan

Question #195045

Vertical Printing

You are given a string(S) with multiple words in it. Return all the words vertically in the same order in which they appear in S.


Complete with spaces when it is necessary while forming the words vertically. (Trailing spaces are not allowed).


Note: All characters in S are upper case.


Input

The first line contains a string S.


Output

Each line of the output contains a string formed vertically as mentioned above.


Explanation

Given S = CAT BAT VIN.


We are expected to print the words vertically such that considering the ith letter in each line of the output will form the ith word in the given input.


Printing the given words vertically


Joining all the first characters from the 3 lines of output gives CAT.

Joining all the second characters from the 3 lines of output gives BAT.

Joining all the third characters from the 3 lines of output gives VIN.


Sample Input 1

CAT BAT VIN

Sample Output 1

CBV

AAI

TTN

Sample Input 2

MAM BY DORM

Sample Output 2

MBD

AYO

M R

M


1
Expert's answer
2021-05-19T15:51:42-0400
s = 'MAM BY DORM'


w = s.split(' ')
for i in range(len(max(w, key=len))):
    for ww in w:
        if i < len(ww):
            print(ww[i], end = '')
        else:
            print(' ', end = '')
    print('')

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