简体   繁体   English

在单词列表后找到字符串中的单词

[英]Find the word in a string after a list of words

my friend and i are studying words and their meaning and i need help trying to get the word that we want to learn about. 我和我的朋友正在研究单词及其含义,我需要帮助以获取我们想要学习的单词。 I have a list of words that we type into the command line that will tell the computer we want the meaning or history of the word we want. 我有一个单词列表,可以在命令行中输入这些单词,告诉计算机我们想要的单词的含义或历史。 My problem is finding out which word we typed in. here is my code so far: 我的问题是找出我们键入的单词。这是到目前为止的代码:

Meaning = {"Meaning", "define", "history"}
text1  = raw_input("Text: ")
tokens = commands.lower().split()
if Meaning.intersection(tokens):
    #Here is the problem, because i don't know what word we might type
    #so i need it to check the word after the Meaning. How can i do this?

I am using the program to type into a website and get information on the word, so i can't add the word and the definition because it would be too hard to do every word i know. 我正在使用该程序键入网站并获取有关单词的信息,所以我无法添加单词和定义,因为很难理解我所知道的每个单词。 How can i get the word after the meaning?, Thank you. 含义之后,我该如何获得这个词?,谢谢。

Set up your dictionary as set of pairs. 将字典设置为成对设置。

terms = {'word1': 'meaning', 'word2': 'othermeaning'}

print terms['word1']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM