简体   繁体   English

如何返回两个不同列表中存在的字符串?

[英]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.

相关问题 如何比较两个不同对象的列表并返回匹配项? - How Can i compare two lists of different objects and return match? 如何获取两个列表中的所有元素以返回一个字符串 - How to get all the elements in two lists to return a string 如何检查两个输入变量是否在两个不同列表中的相同位置并返回有效? - How do I check if two input variables are in the same position in two different lists and return as valid? 返回两个不同列表中两个值之间的索引 - Return an index that is between two values in two different lists 两个具有不同长度的列表,但在检查不同元素时不返回任何内容 - Two lists with different length, but return nothing while checking the different element 将两个不同的值添加到来自不同列表的字符串中 - Add two different values to string from different lists 查找是否在字符串中找到来自两个不同列表的两个元素 - Find if two elements from two different lists are found consequently in a string 我如何比较 2 个不同的字符串列表并在其中一个更大的情况下返回差异? - how do i compare 2 different string lists and return the difference if one is bigger? 如何比较两个字符串列表并返回匹配项 - How to compare two lists of strings and return the matches 如果每个字符串中的索引匹配,如何按索引比较两个 python 列表返回 Boolean? - How can I compare two python lists by index return a Boolean if the index in each string matches?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM