有人可以用示例R / Python代码来解释{{bcz“,u,thr}用{”因为“,你在那里用全文替换吗? (文本明)
答案 0 :(得分:0)
remove_words函数获取一个字符串并返回另一个字符串,并进行所需的更改。确保正确安装了正则表达式包,以便能够运行此代码并获得所需的输出。通过正则表达式,您可以定义编译器以提取您想要更改的每个字符串模式:
import regex as re
def remove_words(my_line):
new_line =''
compiler_thr = re.compile(r"thr")
compiler_u = re.compile(r"u")
compiler_bcz = re.compile(r"bcz")
for i in my_line.split():
if i in compiler_thr.findall(my_line):
new_line = new_line + ' ' + 'there'
elif i in compiler_u.findall(my_line):
new_line = new_line + ' ' + 'you'
elif i in compiler_bcz.findall(my_line):
new_line = new_line + ' ' + 'because'
else:
new_line = new_line + ' ' + i
return new_line