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')
上面的代碼改寫特別是關於含義給出的句子「是」省略了字符串標識'在Python
由於只照顧其先前字,主題,我只冒了一句。 split()[0]並再次評估其含義。
問題是,如果我拿sentence.split()[0],我最終得到「有」作爲一個字符串,但我想再次讓蟒蛇把它讀成一個變量其中包括另一個元組或一組字符串,例如there ='distant place or location',並檢查其中是否存在字符串'place or location'。
其他問題1)先進的方式,我想彌補其落入組所謂地方的一些詞組,如地方= {那裏,這裏}然後讓程序檢查是否句子.split()[0]實際上屬於這個組。
我該怎麼做?
附加問題2)當我引用一個詞的含義時,例如is = {exist,parity}。如果我遵循數學符號注意到它,那麼就沒有給出「順序」,但是如果我將它作爲一個列表或元組,如is =(存在,奇偶性)或is = [存在,奇偶性),那麼不可避免地會出現'order' 。
python中哪個數據結構不包含'order'?
我可以檢查的任何建議或參考?
您可能想使用Python的[詞典]結構(https://docs.python.org/2/tutorial/datastructures.html#dictionaries)結構,雖然我不完全清楚你的東西所需的輸出它。 – asongtoruin
我正在考慮對給定的句子進行修改。 @asongtoruin希望你看到我的答案 – Daschin