I have data that is collected in a loop and stored in separate lists that contain only the same data types (for example, only rows, only floating), as shown below:
names = ['bar', 'chocolate', 'chips']
weights = [0.05, 0.1, 0.25]
costs = [2.0, 5.0, 3.0]
unit_costs = [40.0, 50.0, 12.0]
I considered these lists as “columns” of the table and wanted to print them as a formatted table, which should look something like this:
Names | Weights | Costs | Unit_Costs
----------|---------|-------|------------
bar | 0.05 | 2.0 | 40.0
chocolate | 0.1 | 5.0 | 50.0
chips | 0.25 | 3.0 | 12.0
I only know how to print the data from the lists horizontally in the rows of the table, I looked online (and on this site) for some help regarding this problem, however I managed to find help to make it work in python 2.7 and not 3.5.1 what i use.
my question is:
how to get entries from the lists above to print them in a table as shown above.
Each index of an element from the above lists is associated (that is, record [0] from 4 lists is associated with the same element: bar, 0.05, 2.0, 40.0).
source
share