1

There are 2 dictionaries created: delack_node0 and delack_node1. FOR NODE0 and NODE1

Their values are:

defaultdict(None, {'FC': 0.0, 'NL': 0.0, 'SSD': 11805529.0})
defaultdict(None, {'FC': 0.0, 'NL': 0.0, 'SSD': 13052326.0})

I would like the dictionary values to be printed in the below format, with values shown below FC NL SSD

___Average DelAcks for 5  Iterations___
    Node    FC          NL          SSD
    0

    1  

I used print to try to achieve the above format:

print("___Average DelAcks for", no_of_iterations," Iterations___" )
print("\tNode\t\t\t\tFC\t\t\tNL\t\t\tSSD")
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
redpy
  • 143
  • 5
  • 1
    You'll have to write code that does this. I don't think there's a simple way to get this exact output. You could have a look at [the Rich library](https://github.com/willmcgugan/rich) which provides rich terminal output for Python – ForceBru May 02 '21 at 13:38
  • Can you accept one of the answers if it solved your problem? – Maicon Mauricio Apr 18 '22 at 01:12

2 Answers2

1

You can use a data analysis library like panda to do that. There are various options to pretty-print a data frame. You might find the answers of this question helpful

Asaf Kfir
  • 129
  • 2
  • 9
1

It's actually very easy. You just have to make a list with the dictionaries:

from collections import defaultdict

defaultdicts = [
    defaultdict(None, {'FC': 0.0, 'NL': 0.0, 'SSD': 13052326.0}),
    defaultdict(None, {'FC': 0.0, 'NL': 0.0, 'SSD': 11805529.0}),
]

print("___Average DelAcks for {} Iterations___".format(len(defaultdicts)))

print("{:^10}{:^10}{:^10}{:^10}".format('Node', 'FC', 'NL', 'SSD'))

column = "{:^10}{FC:^10}{NL:^10}{SSD:^10}"

for index, value in enumerate(defaultdicts):
    print(column.format(index, **value))

If you are going to do this a lot I would recommend using pandas as @asaf has said. If this is a silly script installing pandas is unnecessary.

Also this thread on StackOverflow may help you.

PS: The str.format method is very powerful. You should take a look at the python docs.

Maicon Mauricio
  • 2,052
  • 1
  • 13
  • 29