astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.19k stars 165 forks source link

Header on the left #275

Open isidroas opened 1 year ago

isidroas commented 1 year ago

For example:

from codecs import encode
from string import ascii_uppercase

rot13_cipher = [(c, encode(c,'rot13')) for c in ascii_uppercase]
tabulate(rot13_cipher, headers = ('input', 'output'), header_pos='left')

resulting in

+--------++---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| input  || A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
+--------++---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| output || N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C | D | E | F | G | H | I | J | K | L | M |
+--------++---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+

The use case is for small tables. It can save more space in the screen/page using horizontal columns.

isidroas commented 1 year ago

Related to https://github.com/astanin/python-tabulate/issues/237