本文目錄一覽:
- 1、如何用python在一個輸入的中文句子中找到指定的中文字或中文詞組,並做出翻譯?
- 2、怎麼用python re.search找出每個首字母是aeiou的單詞
- 3、用python寫一個找單詞程序。具體如下。。用上提示的函數
- 4、如何用Python語言實現在一個文件中查找特定的字符串?
如何用python在一個輸入的中文句子中找到指定的中文字或中文詞組,並做出翻譯?
可以嘗試 先將str中數據轉換位成 字符編碼,然後使用re 正則匹配並替換對應的譯文。
怎麼用python re.search找出每個首字母是aeiou的單詞
可憐的娃,re.findall更簡單
re.findall(r’\b([aeiou][A-z]*)\b’,’axxx xxx exxxx’)
[‘axxx’, ‘exxxx’]
用python寫一個找單詞程序。具體如下。。用上提示的函數
#!bin/python #-*- encoding: utf-8 -*- def counter(path, find, punctuation): infile = open(path, “r”) lenth = len(find) count = [] for i in range(lenth): count.append(0) dat = infile.readline().strip(“\n”) while dat != ”: dat = dat.split() for elemt in dat: elemt = elemt.strip(punctuation) #去除標點符號 if elemt in find: i = find.index(elemt) count[i] += 1 dat = infile.readline().strip(“\n”) infile.close() for i in range(lenth): print “%s:%d次” % (find[i],count[i]) if __name__ == “__main__”: path = “PATH” find = [“hello”, “hi”, “world”] punctuation = ”’,.;'”:!?”’ counter(path, find, punctuation)
如何用Python語言實現在一個文件中查找特定的字符串?
用正則表達式
s=’hello world’
import re
re.search(‘wor’,s)
_sre.SRE_Match object; span=(6, 9), match=’wor’
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/306562.html