例如,我有以下列表:
full_text = ["This is Archie. He is a rare Norwegian Pouncing Corgo.",
"This is Darla. She commenced a snooze mid meal.",
"Here we have a majestic great"]
我想确定第一个子句包含“He”,第三个子句不包含“He”
但我不知道如何在这段代码中使用正则表达式:
gender = []
for f in full_text:
words = f.split(" ")
if any (["He" in f, "boy" in f, "him" in f, "his" in words]):
gender.append(0)
elif any (["She" in f, "girl" in f, "her" in f, "hers" in words]):
gender.append(1)
else:
gender.append(-1)
我得到的结果是[0,1,1]。我想要的结果是[0,1,-1]
我同意,更一般地说,你的常量,例如
["he", "boy", "him", "his"]
和words
,["here", "we", "have"]
,应该都是小写的相关问题 更多 >
编程相关推荐