Py学习  »  Python

如果python不区分大小写,如何用特定模式替换给定句子中的单词?

Mazil_tov998 • 3 年前 • 1399 次点击  

我被判刑了 我的球队是锦标赛中最好的球队。 作为创建函数的测试用例

def case_insensitivity(sentence):
    return new_sentence

它检查给定句子中不区分大小写的单词,并将不区分大小写的单词替换为 XXX_ .

print(case_insensitivity('My team is the BeST team at the tournament'))
result
'My team is the XXX_ team at the tournament'

最好的方法是什么? casefold()

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131472
 
1399 次点击  
文章 [ 2 ]  |  最新文章 3 年前