當前位置:首頁 » 編程語言 » python不區分大小寫

python不區分大小寫

發布時間: 2025-09-07 05:01:07

python的re,findall 忽略大小寫

沒那幾個人說的那麼麻煩,只需要加一個參數,如下:

import re

SHA = 'AC:B0:F3:26:EA:C1'

result1 = re.findall(r'ac:.*:c1',SHA) # 這樣是搜不到的,因為大小寫不匹配

result2 = re.findall(r'ac:.*:c1',SHA,re.IGNORECASE) # 這是能搜到的,已忽略大小寫

print('未忽略大小寫搜索結果:',result1)

print('忽略大小寫搜索結果:',result2)

結果:

運行結果

⑵ Python實現count_ignore_case(ls,s)函數。返回不區分大小寫相等的元素的數量

def count_ignore_case(ls,s):
dic={}
for i in s:
dic[i]=0
for x in ls:
for y in x:
if y.lower() in dic:
dic[y.lower()]+=1
return dic

print(count_ignore_case(['Count_ignore_case','ABCabbcdefg'],'abc'))

熱點內容
軟考演算法題 發布:2025-09-07 09:11:07 瀏覽:620
android項目總結 發布:2025-09-07 09:08:48 瀏覽:721
除ftp訪問之外還能怎麼訪問 發布:2025-09-07 09:08:48 瀏覽:830
電腦訪問伺服器會出現排隊等待 發布:2025-09-07 08:56:55 瀏覽:618
linux除法 發布:2025-09-07 08:56:13 瀏覽:711
編程小花貓 發布:2025-09-07 08:49:37 瀏覽:243
資料庫或伺服器 發布:2025-09-07 08:45:15 瀏覽:805
hadoop權威指南源碼 發布:2025-09-07 08:31:28 瀏覽:755
光學存儲量 發布:2025-09-07 08:26:23 瀏覽:468
aes加密linux 發布:2025-09-07 08:22:49 瀏覽:138