Mar-02-2019, 06:55 PM
Well, looking at your code, you are actually working in 2D. Your matrices are stored as a list of lists. So you can just use the code I showed you. Note that it will give you a generator, not a list, but you can fix that by doing
The reason it works is that zip takes any number of lists as parameters. It then returns a list of the first item in each list, a list of the second item in each list, a list of the third item in each list, and so on. The star (*) notation converts a sequence (like a list) into a series of parameters.
transposed = list(zip(*matrix))
The reason it works is that zip takes any number of lists as parameters. It then returns a list of the first item in each list, a list of the second item in each list, a list of the third item in each list, and so on. The star (*) notation converts a sequence (like a list) into a series of parameters.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures