【问题标题】:Dictionary list how to compare probability and class type字典列表如何比较概率和类别类型
【发布时间】:2021-12-22 07:19:35
【问题描述】:

简单的 python 问题,但我似乎仍然无法正确回答。

ints = [{'intent': 'goodbyes', 'probablility': '0.43079117'}, {'intent': 'compliments', 'probablility': '0.3078408'}]

#how do i check that intent = goodbyes AND probability is > than 0.5 

【问题讨论】:

  • [entry for entry in ints if entry['intent'] == 'goodbyes'] and float(entry['probability']) > 0.5]
  • 结果应该是什么?条件成立的要素是什么?条件是否适用于任何或所有元素?

标签: python json list


【解决方案1】:

def check_intent(ints):
    for i in ints:
        if i['intent'] == 'goodbyes' and i['probablility'] > 0.5:
            return True
    return False

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2018-12-24
    • 2023-03-12
    • 1970-01-01
    • 2012-02-21
    • 2021-06-24
    相关资源
    最近更新 更多