我是python的新手,我想只返回单词中的元音,但每个单词的元音都有自己的行。
import sys
import re
line = sys.stdin.readline()
pattern = re.compile("[a-zA-Z0-9]+")
while line:
for word in pattern.findall(line):
for letter in word:
if letter in ('aeiouAEIOU'):
print(letter.lower(), end="")
line = sys.stdin.readline()
如果输入是文本文件:
cat
CHO
tree
guess!
bear"
我想返回:
a
o
ee
ue
ea
现在我得到:
aoeeueea
答案 0 :(得分:1)
您可以在外循环的末尾打印换行符:
while line:
for word in pattern.findall(line):
for letter in word:
if letter in ('aeiouAEIOU'):
print(letter.lower(), end="")
print()
line = sys.stdin.readline()
答案 1 :(得分:0)
while line:
for word in pattern.findall(line):
print(''.join(letter.lower() for letter in word if letter.lower() in "aeiou"))
line = sys.stdin.readline()