Post Reply 
Programming puzzles: processing lists!
01-28-2019, 08:22 PM
Post: #257
RE: Programming puzzles: processing lists!
(01-28-2019 07:37 PM)pier4r Wrote:  List transpose?

Maybe a bit off topic, but here's a party trick to transpose a matrix in Python:
Code:
>>> matrix = [[1, 34, 46, 31], [32, 40, 82, 40], [30, 16, 24, 18]]
>>> zip(*matrix)
[(1, 32, 30), (34, 40, 16), (46, 82, 24), (31, 40, 18)]

Found in: Dissecting a code golf challenge

Cheers
Thomas

BTW: The matrix is a list.
Code:
>>> type(matrix)
<type 'list'>
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming puzzles: processing lists! - Thomas Klemm - 01-28-2019 08:22 PM



User(s) browsing this thread: 3 Guest(s)