Created
July 14, 2011 11:36
-
-
Save mapio/1082301 to your computer and use it in GitHub Desktop.
Trasposizione tabella LaTeX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# salva questo in un file "pippo.py" ed eseguilo da riga di comando con "python pippo.py" | |
# metti la tua tabella tra le triple virgolette | |
table = r""" | |
a & b & c & d \\ | |
e & f & g & h \\ | |
i & j & k & l | |
""" | |
# matrix contiene gli elementi della tabella in una matrice (lista di liste) | |
matrix = [ map( lambda _ : _.strip(), line.strip( r'\\').split( '&' ) ) for line in table.splitlines() if line ] | |
# transposed_matrix è la sua trasposta | |
transposed_matrix = zip( *matrix ) | |
# transposed_table è la tabella trasposta in LaTex | |
transposed_table = ' \\\\\n'.join( ' & '.join( _ ) for _ in transposed_matrix ) | |
# taglia e incolla il risultato | |
print transposed_table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Se lo lanci, produce
a & e & i
b & f & j
c & g & k
d & h & l