在 python 中查找子字符串的两个字符串列表之间的比较

Comparison between two lists of strings for finding substring in python

import tkinter as tk
import speech_recognition as sr
from tkinter import ttk
import tkinter.messagebox
import nltk
from tkinter import *
#--------------1stfile---------------
r = sr.Recognizer()
file = sr.AudioFile("t.wav")
with file as source:
audio = r.record(source, duration=20)
result = r.recognize_google(audio)

with open("audio.txt", "w") as text_file:
  text_file.write("%s" % result)
with open("audio.txt", "r") as file:
  file_content = file.read()
tokens = nltk.word_tokenize(file_content)
print("tokens", tokens)
text_file.close()

def onclick():
 a=1
 tk.messagebox.showinfo("Phrased entered by user : ", phrase_var.get())
 str = phrase_var.get()
 list2 = list(str.split(" "))
 length=len(list2)
 count=0
 for i in tokens:
    for j in list2:
        if(j==i):
            count=count+1
            break
 print(count)
 if(length==count):
    tk.messagebox.showinfo("result", " Phrase " + phrase_var.get() + 
"found in file")


window = tk.Tk()
window.title("Desktop App")
window.geometry("500x500")
window.configure(bg='brown')
ttk.Label(window, text="Write phrase: ").pack()
phrase_var = tk.StringVar()
phrase_entrybox = ttk.Entry(window, width=16, 
textvariable=phrase_var).pack()
ttk.Label(window, text=result).pack()
ttk.Button(window,text="Search", command=onclick).pack()
window.mainloop()

我有两个单独的列表,其中包含 it.one 中的字符串,其中一个较大,而另一个较小,我想检查列表中较小字符串中存在的字符串是否存在于较长列表中下面是一些示例,请帮助我找到解决方案 更长的列表: '['how', 'many', 'people', 'are', 'there', 'in', 'your', 'family', 'there', 'are', 'five', 'people'、'in'、'my'、'family'、'my'、'father'、'mother'、'brother'、'sister', 'and', 'me', 'house'、'in'、'the'、'countryside']' 较小的列表: ['people'、'in'、'my'、'family']

可以使用set

issubset方法
if set(smaller_list).issubset(set(larger_list)):
    ## Your code

这将检查 smaller_list 中存在的所有元素是否也存在于 larger_list 中。简而言之,它检查 smaller_list 是否是 larger_list

的子集