Character Alignment

0

I would like someone to tell me how I can get the numbers to align this way with the words from the top index, I'm doing a replica of this example for a college job, but I can not get numbers to align without ever expanding to off the screen. I'm using pyhton 3.4.

Thanks if you can help me

    
asked by anonymous 02.04.2016 / 06:48

1 answer

1

You can use the tabulate library to adapt your need, see an example use based on some data that you introduced:

>>> from tabulate import tabulate
>>> data = [[2000, 0.00, 0.01, 0.00, 0.00, 1485, 2128, 79, 286], [4000, 0.01, 0.02, 0.00, 0.00, 2286, 4673, 264, 92]]
>>> headers = ['n', 'Insercao', 'Selecao', 'Merge', 'Quick', 'Insercao', 'Selecao', 'Merge', 'Quick']
>>> print(tabulate(data, headers, tablefmt='psql'))
+------+------------+-----------+---------+---------+------------+-----------+---------+---------+
|    n |   Insercao |   Selecao |   Merge |   Quick |   Insercao |   Selecao |   Merge |   Quick |
|------+------------+-----------+---------+---------+------------+-----------+---------+---------|
| 2000 |       0    |      0.01 |       0 |       0 |       1485 |      2128 |      79 |     286 |
| 4000 |       0.01 |      0.02 |       0 |       0 |       2286 |      4673 |     264 |      92 |
+------+------------+-----------+---------+---------+------------+-----------+---------+---------+
    
02.04.2016 / 22:58