我所拥有的是:
present_tense = ["say","make","go",'take','come','see',"know", "get", "give", "find", "think", "tell", "become", "feel", "leave"]
past_tense = ["said","made",...]
我希望程序搜索raw_input中引入的单词是否在present_tense
中,如果是,则检索位于相同位置的past_tense
列表中的元素。
目前这就是我所拥有的,但我想有一种巧妙的方式。
def pasttense(verb):
if verb in present_tense [0]:
pastform = "said"
elif verb in present_tense [1]:
pastform = "made"
elif verb in present_tense [2]:
pastform = "went"
elif verb in present_tense [3]:
pastform = "took"
答案 0 :(得分:0)
尝试这样的事情
pastform = past_tense[present_tense.index(verb)]
但如果verb
不在present_tense
,则引发异常
因此,如果不期望例外情况,您可以在verb
present_tense
if verb in present_tense:
pastform = past_tense[present_tense.index(verb)]