社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Mazil_tov998 • 3 年前 • 1356 次点击  

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

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
 
1356 次点击  
文章 [ 2 ]  |  最新文章 3 年前