"mary" <mary.stern at virgin.net> wrote in message news:9c50pc$5vtg$1 at sp15at20.hursley.ibm.com... > I have a simple problem and am interested to find > the 'best' way to do this in python: > > Given a list such as: > > x[0] = (1,2,3) > x[1] = (4,5,6) > x[2] = (7,8,9) > > what's the best way to 'take vertical slices' from this > matrix, ie end up with: > > y[0] = (1,4,7) > y[1] = (2,5,8) > y[2] = (3,6,9) List comprehensions may be simplest: y = [ [x[i][j] for j in range(3)] for i in range(3) ] but they'll give you lists, not tuples as in your example's notation; you'll have to explicitly use the tuple builtin for transformation if you do require tuples. Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4