[英]how to Return a string that is pressent in two different lists?
Hi I'm new to python and I'm making a voice assistant.嗨,我是 python 的新手,我正在做一个语音助手。
The Voice string contains what I've said using speech.recognition. Voice 字符串包含我使用 Speech.recognition 所说的内容。
I was thinking to split the Voice string into a list and return the string that match.我正在考虑将语音字符串拆分为一个列表并返回匹配的字符串。
For example: Voice = "Hi, could you research this and that on google"例如:Voice =“嗨,你能在谷歌上研究这个和那个吗”
I asked it in a different way, but I think I didn't ask properly what I was looking for.我以不同的方式问它,但我认为我没有正确地问我在寻找什么。 How to use any string from list as a variable?
如何使用列表中的任何字符串作为变量?
Voice_List = Voice.split()
List_A = ["research", "search"]
List_B = ["on google", "using google", "with google"]
Word_A = any_word in Voice_List AND in List_A
Word_B = any_word in Voice_List AND in List_B
webbrowser.get().set(anything between Word_A and Word_B)
I think in this case you can specify your voice list as a set as well as your list_a or list_b as another set.我认为在这种情况下,您可以将您的语音列表指定为一个集合,并将您的 list_a 或 list_b 指定为另一个集合。 Then you can apply the intersection function directly.
然后你可以直接申请交集 function。
Voice_Set = set(Voice.split())
Set_A = set(["research", "search"])
Set_B = set(["on google", "using google", "with google"])
Word_A = Voice_Set.intersection(Set_A)
Word_B = Voice_Set.intersection(Set_B)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.