Home > Back-end >  How to print specific values from dict_items?
How to print specific values from dict_items?

Time:07-12

I have a dict_items called results which contains the following:

dict_items([('rouge-1', {'r': 1.0, 'p': 1.0, 'f': 0.999999995}), ('rouge-2', {'r': 1.0, 'p': 1.0, 'f': 0.999999995}), ('rouge-l', {'r': 1.0, 'p': 1.0, 'f': 0.999999995})])

What I want to do is to extract the values of f from all items rouge-1, rouge-2 and rouge-l

How can I do it?

CodePudding user response:

Try:

results = get_scores()  # <-- the results contains your dict_item(...)

for k, v in results:
    print(k, v["f"])

CodePudding user response:

for name in ('rouge-1','rouge-2','rouge-l'):
    print( dict_items[name]['f'] )

If you want ALL of the items, there's an easier way;

for k,v in dict_items.items():
    print(k, v['f'])
  • Related