[英]How can i add cheque in dictionary?
I am trying to extract the duplicates keys from dictionary which has confidence greater than 0.20.我正在尝试从置信度大于 0.20 的字典中提取重复键。 I think there is a need of else statement in remove_object_all_lists variable
but i dont know how to write i am getting error我认为remove_object_all_lists variable
中需要 else 语句,但我不知道如何写我收到错误
iou_score_of_keys = {'couch': 0.591, 'couch001': 0.11, 'chair': 0.85, 'couch002': 0.221}
highest_score_overlapping = []
highest_score_overlapping = [{key:value} for key, value in iou_score_of_keys.items() if iou_score_of_keys[key] > 0.20]
check_dict_keys = [" ".join(re.findall("[a-zA-Z]+", list(iterate.keys())[0])) for iterate in highest_score_overlapping]
removed_object_all_lists = [list(iter.keys()) for iter in (highest_score_overlapping) if all(x==check_dict_keys[0] for x in check_dict_keys) == True]
Expected_output:预期输出:
['couch' , 'couch002']
Note: Regular expression applied due to remove the numbers from string as it was applied intentionally and now to remove it for get same key注意:由于从字符串中删除数字而应用正则表达式,因为它是有意应用的,现在删除它以获得相同的密钥
This looks pretty convoluted.这看起来很复杂。 Why don't you try something like this:你为什么不尝试这样的事情:
# Filter keys with high scores into a list
highest_score_overlapping = [
key for key, score in iou_score_of_keys.items() if score > 0.20
]
# Aggregate the corresponding keys
trans = {ord(c): "" for c in "0123456789"}
counts = {}
for key in highest_score_overlapping:
counts.setdefault(key.translate(trans), []).append(key)
# Fetch the multiples
result = [key for keys in counts.values() if len(keys) > 1 for key in keys]
Result for your input:您输入的结果:
['couch', 'couch002']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.