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
The first line contains a string
Each line of the output contains a string formed vertically as mentioned above.
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
from itertools import zip_longest
S = input()
lst = map(list, S.split())
for item in zip_longest(*lst, fillvalue=' '):
print(' '.join(item))
Comments
Leave a comment