fork download
  1. from itertools import zip_longest
  2.  
  3. def transpose(n):
  4. lines = map(list, n.splitlines())
  5. transp = list(zip_longest(*lines, fillvalue=' '))
  6. print('\n'.join([''.join(line).rstrip() for line in transp]))
  7.  
  8. def transpose_one_line(n):
  9. print('\n'.join([''.join(line).rstrip() for line in list(zip_longest(*list(map(list, n.splitlines())), fillvalue=' '))]))
  10.  
  11.  
  12.  
  13. print('\n-------Simple Test:-------\n')
  14. n1 = """Some
  15. text."""
  16. transpose(n1)
  17.  
  18. print('\n-------Advanced Test:-------\n')
  19. n2 = """package main
  20.  
  21. import "fmt"
  22.  
  23. func main() {
  24. queue := make(chan string, 2)
  25. queue <- "one"
  26. queue <- "twoO"
  27. close(queue)
  28. for elem := range queue {
  29. fmt.Println(elem)
  30. }
  31. }"""
  32. transpose(n2)
Success #stdin #stdout 0.02s 9936KB
stdin
Standard input is empty
stdout
-------Simple Test:-------

St
oe
mx
et
 .

-------Advanced Test:-------

p i f       }
a m u
c p n
k o c
a r  qqqcf }
g t muuulo
e   aeeeor
  " iuuus
m f neeeeef
a m (   (lm
i t ):<<qet
n "  =--um.
    {   e P
     m""u:r
     aote=i
     knw) n
     eeo rt
     ("O al
     c " nn
     h   g(
     a   ee
     n    l
         qe
     s   um
     t   e)
     r   u
     i   e
     n
     g   {
     ,

     2
     )