I have a list of items sorted alphabetically:
mylist = [a,b,c,d,e,f,g,h,i,j]
I'm able to output the list in an html table horizonally like so:
| a , b , c , d |
| e , f , g , h |
| i , j , , |
What's the algorithm to create the table vertically like this:
| a , d , g , j |
| b , e , h , |
| c , f , i , |
I'm using python, but your answer can be in any language or even pseudo-code.
>>> l = [1,2,3,4,5,6,7,8,9,10]
>>> [l[i::3] for i in xrange(3)]
[[1, 4, 7, 10], [2, 5, 8], [3, 6, 9]]
Replace 3
by the number of lines you want as a result:
>>> [l[i::5] for i in xrange(5)]
[[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With