从使用process.entract中存储在字典中的模糊匹配的结果中获取索引。

发布于 2025-02-09 01:34:02 字数 1049 浏览 0 评论 0原文

使用以下代码,我能够从字典,find_desc_dict中获得模糊的匹配结果,并将其存储在另一个称为plumpty_dict的字典中。

for i, a in enumerate(recognized_keywords_search_desc):
    complete_dict[i+1] = process.extract(search_desc_list[i], find_desc_dict, limit=10, scorer=fuzz.token_sort_ratio)

这是一个示例,以澄清键值对在complete_dict中的样子:

{1: [('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), 2: [('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92)},

基本上,完整_dict的输出结构为{键:[(字符串,比例,索引),(字符串,比率,索引),...((字符串,比率,索引)],键:[(字符串,比率,索引),(字符串,比率,索引),...,(字符串,比率,索引)]}。我想了解如何仅在完整_Dict中存储索引。

Using the below code, I was able to get the fuzzy-ly matched results from a dictionary, find_desc_dict, and store it inside another dictionary called complete_dict.

for i, a in enumerate(recognized_keywords_search_desc):
    complete_dict[i+1] = process.extract(search_desc_list[i], find_desc_dict, limit=10, scorer=fuzz.token_sort_ratio)

Here is an example as to clarify what the key-value pairs look like in complete_dict:

{1: [('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), ('some string', 72, 19), ('some other string', 72, 20), 2: [('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92), ('some string', 89, 205), ('some other string', 71, 92)},

Basically the output structure of complete_dict is {key: [(string, ratio, index), (string, ratio, index), ... , (string, ratio, index)], key: [(string, ratio, index), (string, ratio, index), ... , (string, ratio, index)]} . I would like to learn how I can get just the indexes stored inside complete_dict.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2025-02-16 01:34:02

因此,出于我的目的,我找到了以下代码正常工作并返回所有索引的列表。当然,哪些索引属于什么钥匙的问题。答案是前10个元素将与密钥#1相对应,第二个10个元素将与密钥#2相对应,依此类推。也可以在以后将列表转换为字典,或将索引存储在词典中。

indexes2workwith = []
for i, a in enumerate(complete_dict):
  for x in range(10): 
    indexes2workwith.append((((complete_dict[i+1]).pop(0))[2]))

So for my purposes I found the below code to work fine and return a list with all of the indexes. Granted, questions of which indexes belong to what key come to mind. The answer to that would be the first 10 elements would correspond to the key#1, the second 10 elements would correspond to the key#2 and so forth. It's also possible to convert the list into a dictionary later or store the indexes in a dictionary to begin with.

indexes2workwith = []
for i, a in enumerate(complete_dict):
  for x in range(10): 
    indexes2workwith.append((((complete_dict[i+1]).pop(0))[2]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文