【发布时间】:2017-07-19 13:15:32
【问题描述】:
def Interpretation_is(sentence):
print(sentence.split())
print(sentence.split()[0])
there = 'distant place'
he = 'gender identity'
if 'place' in setence.split()[0]:
print(sentence.replace('is','exists'))
if 'identity' in sentence.split()[0]:
print(sentence.replace('is','equal to'))
Interpretation_is('there is a woman')
Interpretation_is('he is a boy')
上面的代码专门针对“是”的含义改写给定的句子
由于只关心它的前一个词,主语,所以我只取了 sentence.split()[0] 并再次评估它的含义。
问题是,如果我取 sentence.split()[0],我最终会得到 'there' 作为字符串,但我想再次让 python 将其读取为 由另一个元组或字符串集合组成的变量,例如there = 'distant place or location',并检查其中是否存在字符串'place or location'。
附加问题 1) 以一种高级的方式,我想组成一些属于所谓的 place 组的词组,例如 place = {there, here} 然后让程序检查 sentence.split()[0] 是否真的属于这个组。
我该怎么做?
附加问题 2) 当我引用一个词时,如 is = {exist, parity}。如果我按照数学符号记下它,则没有给出“顺序”,但是如果我将其作为列表或元组,例如 is = (exist, parity) 或 is = [exist, parity],则不可避免地会给出“顺序” .
python 中的哪个数据结构中不包含“顺序”?
我可以查看任何建议或参考资料吗?
【问题讨论】:
-
您可能想研究使用 Python 的 dictionary 结构,但我并不完全清楚您想要的输出。
-
我正在考虑对给定句子进行改写。 @asongtoruin 希望你能看到我的回答
标签: python string list data-structures