0

Pythonを使用して、リスト内の同様のアイテムを探す必要があります。(たとえば、'Limits' は 'Limit' に似ています。または 'Download ICD file' は 'Download ICD zip file' に似ています) 数値ではなく、文字で結果を類似させたいと思っています (たとえば、'Angle 1' は「角度 2」)。リスト内のこれらの文字列はすべて「\0」で終わります

私がやろうとしているのは、すべての項目を空白で分割し、数字で構成されている部分があるかどうかを調べることです。しかし、どういうわけか、私はそれを機能させたいので機能していません。

これが私のコード例です:

for k in range(len(split)):  # split already consists of splitted list entry
    replace = split[k].replace(
        "\\0", ""
    )  # replace \0 at every line ending to guarantee it is only a digit
    is_num = lambda q: q.replace(
        ".", "", 1
    ).isdigit()  # lambda i found somewhere on the internet
    check = is_num(replace)
    if check == True:  # break if it is a digit and split next entry of list
        break
    elif check == False:  # i know, else would be fine too
        seq = difflib.SequenceMatcher(a=List[i].lower(), b=List[j].lower())
        if seq.ratio() > 0.9:
            print(Element1, "is similar to", Element2, "\t")
            break
4

1 に答える 1