0

Please help, ive been battling with this for ages. I have a code:

contents =[     
        [0, 3, 1, 1, 6, 3, 7, 5, 2, 4, 1],
        [0, 3, 4, 5, 11, 14, 21, 26, 28, 32, 33],
        [4, 2, 3, 2, 3, 4, 2, 4, 5, 3, 4],
        [0, 1, 2, 4, 0, 0, 0, 0, 2, 3, 5],
        [0, 4, 6, 9, 11, 14, 21, 26, 30, 35, 38],
        [4, 6, 9, 11, 14, 18, 23, 30, 35, 38, 42],
        [4, 3, 5, 6, 3, 4, 2, 4, 7, 6, 9],
        [0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0],
    ]

and i want to print it like for example: code is:

alpha = [
    ["a", "b", "c", "d", "e"],
    ["f", "g", "h", "i", "j"],
    ["k", "l", "m", "n", "o"],
]

result should look like:

["a", "f", "k"] 
["b", "g", "l"] 
["c", "h", "m"] 
["d", "i", "n"] 
["e", "j", "o"] 
tushortz
  • 3,697
  • 2
  • 18
  • 31

1 Answers1

3

This is easily achieved with a zip.

for row in zip(*contents):
    print(row)

This prints:

(0, 0, 4, 0, 0, 4, 4, 0)
(3, 3, 2, 1, 4, 6, 3, 0)
(1, 4, 3, 2, 6, 9, 5, 0)
(1, 5, 2, 4, 9, 11, 6, 0)
(6, 11, 3, 0, 11, 14, 3, 0)
(3, 14, 4, 0, 14, 18, 4, 0)
(7, 21, 2, 0, 21, 23, 2, 3)
(5, 26, 4, 0, 26, 30, 4, 3)
(2, 28, 5, 2, 30, 35, 7, 0)
(4, 32, 3, 3, 35, 38, 6, 0)
(1, 33, 4, 5, 38, 42, 9, 0)
Blair
  • 6,623
  • 1
  • 36
  • 42