-1

我正在尝试匹配 2 个单独数据集中的字段。它们都是地址字段。一个数据集可能包含“532 Sheffield Dr”之类的内容,而另一个数据集可能仅包含“Sheffield Dr”。另一个例子是“US21 Ramp and Hays RD”和“US 21”,“N 25th St and Danville RD”和“25th St”等等。所以基本上,即使第一个数据集中的数据可能包含一些额外的文本/数字,第二个数据集中列中的所有文本/数字都应该与第一个数据集的匹配。我一直在尝试使用 RegEx,但无法找出合适的代码。我该怎么做?

4

1 回答 1

0

根据您的示例,我理解最简单的方法是:

s1 = ["532 Sheffield Dr",  "US21 Ramp and Hays RD",  "N 25th St and Danville RD"]
s2 = ["Sheffield Dr",  "US 21", "25th St"]

for item2 in s2:
    for item1 in s1:
        if item2 in item1 or item2.replace(' ', '') in item1:
            print('%s in %s' % (item2, item1))
于 2017-04-20T18:45:16.747 回答