【问题标题】:How to print specific values from dict_items?如何从 dict_items 打印特定值?
【发布时间】:2022-07-12 03:08:43
【问题描述】:

我有一个名为 results 的 dict_items,其中包含以下内容:

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})])

我想做的是从rouge-1rouge-2rouge-l的所有项目中提取f的值

我该怎么做?

【问题讨论】:

    标签: python dictionary


    【解决方案1】:
    for name in ('rouge-1','rouge-2','rouge-l'):
        print( dict_items[name]['f'] )
    

    如果你想要所有的项目,有一个更简单的方法;

    for k,v in dict_items:
        print(k, v['f'])
    

    【讨论】:

      猜你喜欢
      • 2017-07-19
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 2015-10-13
      相关资源
      最近更新 更多