需求: 統計一篇完全由英文構成的文章中的單詞的個數
分析:需要判斷什麼是單詞,並統計判斷爲單詞的元素的個數
需要: Python 正則表達式
簡單例子:
import re pattern = re.compile(r'\w+') pattern.match('hello ,world') words = pattern.findall('hello hello world') len(words)
需求: 統計一篇完全由英文構成的文章中的單詞的個數
分析:需要判斷什麼是單詞,並統計判斷爲單詞的元素的個數
需要: Python 正則表達式
簡單例子:
import re pattern = re.compile(r'\w+') pattern.match('hello ,world') words = pattern.findall('hello hello world') len(words)