【发布时间】:2019-11-29 17:08:59
【问题描述】:
我有一段文字。我想计算 2 个单词的所有可能组合(2 个单词必须彼此相邻) 例如:
"I have 2 laptops, I have 2 chargers"
结果应该是:
"I have": 2
"have 2": 2
"2 laptops": 1
"Laptops, I": (Dont count)
"2 chargers": 1
我尝试了正则表达式,但问题是它不会两次计算一个字符串
我用过:\b[a-z]{1,20}\b \b[a-z]{1,20}\b
文字:cold chain, energy storage device, industrial cooling system
它几乎可以工作,但它不包括诸如“存储设备”、cooling system 之类的词,因为它已经使用了energy storage 和industrial cooling
感谢您的建议
【问题讨论】:
标签: python regex pattern-matching frequency word-count