首页 > 解决方案 > 一个巨大的嵌套列表与另一个巨大的嵌套列表的元素的近似比较

问题描述

我有两个嵌套列表,其中一个包含元素。其他10K x 6嵌套列表有28K * 15元素。

这是我使用嵌套循环进行近似比较的伪逻辑

if nested_list_1[iter_1][0] and nested_list_1[iter_2][3] appoximate_ratio > 85:
    if nested_list_1[iter_1][2] and nested_list_1[iter_2][4] appoximate_ratio > 85:
        save_to_another_list

我可以使用嵌套循环遍历每个元素并进行近似比较。但这需要很多时间。有没有办法减少消耗时间?

for i in range(len(nested_list_1)): #length 10000
    data_1_part_1 = nested_list_1[i][0] 
    data_1_part_2 = nested_list_1[i][1] 

    for j in range(len(nested_list_2)): #length 28000
        data_2_part_1 = nested_list_2[j][9] 
        data_2_part_2 = nested_list_2[j][15]

        if fuzzy_ratio(data_2_part_1,data_1_part_1) > 85:

            if fuzzy_ratio(data_2_part_2,data_1_part_2) > 85:

                writing_csv_file(nested_list_1[i])

标签: pythonnested-listsfuzzy-comparison

解决方案


推荐阅读