にリスト内にすでに存在しているときはFalse取得私は、文字列かの条件のためそれは文字列のpython
item1="Act the way that the people around you are acting."
とリスト
list1=['Act the way that the people around you are acting.', "This phrase might come in handy when you're traveling abroad notice that people do things differently than you're used to."]
を持って、
if item1 in list1:
print(item1)
常に失敗しますが、文字列はリストに存在します。これはリスト1にITEM1がTrueになっていません参照してください
Actual code:
df1,
Proverb | Meaning
When in Rome, do as the Romans | Act the way that the people around you are acting. This phrase might come in handy when you're traveling abroad notice that people do things differently than you're used to.
df2,
Meaning
Act the way that the people around you are acting. |
df1_list=df1['Meaning'].values.tolist()
df2_list=df2['Meaning'].values.tolist()
df3=pd.DataFrame(columns=["Proverb","Meaning"])
for item in df2_list:
new_items = nltk.sent_tokenize(item)
for item1 in new_items:
for item2 in df1_list:
list1=nltk.sent_tokenize(item2)
index=None
if item1 in list1:
index=df1_list.index(item2)
data=df1.iloc[[index]]
df3=df3.append(data)
print(df3)
output
df3,
Empty DataFrame
Columns: [Proverb, Meaning]
Index: []
を助け、
最後のループの前に 'list1'を、そしてループの中に' item1'を印刷して、一致しない理由を比較してください。 – PRMoureu