![](/img/trans.png)
[英]What is the most efficient way to find all files containing given string, case-insensitive using Python 3
[英]How to find all occurences of string (case-insensitive) in a file, python?
我有以下代码来找到文件中的字符串并计算完全匹配的次数:
counter+=book.read().count(word)
我想做的是计算单词(存储在变量单词中-这是for循环的一部分)出现的次数,但不区分大小写。
有谁知道如何做到这一点?
将两个字符串都转换为小写:
counter+=book.read().lower().count(word.lower())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.