Answer to Question #194976 in Python for J NAGAMANI

Question #194976

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


CBV

AAI

TTN


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




1
Expert's answer
2021-05-20T20:20:24-0400
from itertools import zip_longest
S = input()
lst = map(list, S.split())
for item in zip_longest(*lst, fillvalue=' '):
    print(' '.join(item))

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