I have a set of data
data = (1,2,3,4,5,6,7,8,9,10)
Usually in python I’ll group these for display across row of n columns:
cols = 4
grouped = izip_longest(*(iter(data),)*cols)
That gives me a great row display:
grouped = ( (1,2,3,4), (5,6,7,8), (9,10,None,None) )
which , on a templated website, would look like
1 2 3 4
5 6 7 8
9 10
Now i’m trying to wrap my head around a different display – down the column & across n rows
1 4 7 10
2 5 8
3 6 9
because this is for web templating, I need to generate a set of this data :
grouped = ( (1,4,7,10), (2,5,8,None), (3,6,9,None) )
Honestly, I’m at a complete loss on how to best approach this.
All you need is a call to
zip():Basically, it uses exactly the same algorithm as yours, and then transposes the result.