0
matrix = [['*','*','*'],
          ['*','*','*']]
t_matrix = [['*','*'],
            ['*','*'],
            ['*','*']]
print(list(zip(*matrix)))
[('*', '*'), ('*', '*'), ('*', '*')]

The above is what happens. I want the matrix to look like t_matrix, but it doesn't. How can I do the transposition?

Chris
  • 26,361
  • 5
  • 21
  • 42

1 Answers1

0

Just use a list comprehension to map each tuple to a list.

print([[a, b] for a, b in zip(*matrix)])

More generally:

print([list(x) for x in zip(*matrix)])
Chris
  • 26,361
  • 5
  • 21
  • 42