python - 查找元音:重新编译模式不将单词的元音保持在一起
问题描述
这是我的代码:
import re
line = ("hello moose pole cccttt.ggg cat cow car horse dddfff arizona mississippi cleveland")
pattern = re.compile("[aAeEiIoOuU*]+", re.IGNORECASE)
while line:
for word in pattern.findall(line):
print(word+"\t"+"1")
line = sys.stdin.readline()
出来的输出是:
想要达到:
eo 1
ooe 1
oe 1
1
a 1
o 1
a 1
oe 1
1
aioa 1
iiii 1
eea 1
注意:假设为没有元音的单词记录一个空白。至少我想收集元音。然后我可以解决非元音词的问题。
解决方案
您正在寻找:
首先创建一个拆分值,冒号
a = re.sub('[^aeiou:]', '', re.sub(' +', ':', line), flags = re.I).split(':')
for word in a: print(word+"\t"+"1")
eo 1
ooe 1
oe 1
1
a 1
o 1
a 1
oe 1
1
aioa 1
iiii 1
eea 1
推荐阅读
- ios - 无法从子视图连接文本字段
- java - Java Swing GUI 未显示使用多个类
- python - Sklearn Chi2 用于特征选择
- function - 响应变量值相等的逻辑回归 - 使用 Microsoft R 客户端
- pyqt - pyqt4滚动条不可见
- css - 让一个 div 向上滑动,等待 5 秒,然后使用 CSS Animation 向下滑动
- java - 添加 jgit 作为 gradle 依赖项可以防止我的主类成为加载器
- bluetooth - 这真的是通过 BLE 发送数据的正确方法吗?(使用 Adafruit 示例作为参考)
- clang - clang 工具:包含路径
- neural-network - 如何在遗传算法中交叉