我有一个元组列表:
ee = [('noise', 0.7592900395393372), ('***roice***', 0.638433039188385), ('voice', 0.7524746060371399), ('***choice***', 0.638433039188385)]
从这里,我只想提取包含以***开头的模式的元组
预期产出:
ee = [('***roice***', 0.638433039188385), ('***choice***', 0.638433039188385)]
我尝试了下面的正则表达式,但它只捕获带***的单词,而不是整个元组,也就是说,我还希望在包含***的元组中出现数字
迄今为止的代码:
yy= []
for i in ee:
t9 = re.findall("[***@*&?].*[***@*&?, ]", str(i))
# for m in t9.finditer(t9):
# print(m.start(), m.group())
#
# print(t9)
for em in t9:
yy.append(em)
有人能帮我修一下吗
您可以尝试:
输出:
如果需要提取0元素以
***
开头和结尾的元组, 您可以尝试以下方法:这不使用正则表达式
我不确定在这种情况下你是否需要正则表达式。如果您只想过滤以“***”开头的字符串,只需执行以下操作:
如果仍要使用正则表达式,可以执行以下操作:
相关问题 更多 >
编程相关推荐