[Zope] How to transpose a 2-D array?

Hannu Krosing hannu@tm.ee
Fri, 05 May 2000 12:05:17 +0300


Jason Wong wrote:
> 
> Question: How do I transpose the contents of a 2-D array?
<dtml-var standard_html_header>
<dtml-call "REQUEST.set('m',[[1,2,3],[4,5,6],[7,8,9],[10,11,12]])">

<table border=1>
<tr><th colspan="<dtml-var "_.len(m[0])+1">">STRAIGHT</th></tr>
<dtml-in m>
<dtml-call "REQUEST.set('row',_['sequence-index'])">
<tr>
<dtml-in sequence-item>
<dtml-call "REQUEST.set('col',_['sequence-index'])">
<td>[<dtml-var row>:<dtml-var col>] <dtml-var "m[row][col]"></td>
</dtml-in>
</tr>
</dtml-in>
</table>

<table border=1>
<tr><th colspan="<dtml-var "_.len(m)+1">">TRANSPOSED</th></tr>
<dtml-in "m[0]">
<dtml-call "REQUEST.set('col',_['sequence-index'])">
<tr>
<dtml-in m>
<dtml-call "REQUEST.set('row',_['sequence-index'])">
<td>[<dtml-var row>:<dtml-var col>] <dtml-var "m[row][col]"></td> 
</dtml-in>
</tr>
</dtml-in>
</table>

</p>
<dtml-var standard_html_footer>
----------------
Hannu