4
Python编程8——Python寻找单词中符合顺序的元音字母
source link: https://iphyer.github.io/blog/2013/01/13/pythonfindpartsinword/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Python编程8——Python寻找单词中符合顺序的元音字母
程序的目的就是标题。
#to find a word that contians the specific parts in it
#in this case it is "aeiou" , all the Vowel letters
datafile=open("dictionary.txt","r")
def cleanWord(word):
"""Return word in lower case without whitespace"""
return word.strip().lower()
def getVowelsInword(word):
vowelsStr="aeiou"
vowelsInword=""
for char in word:
if char in vowelsStr:
vowelsInword+=char
return vowelsInword
#main program
print "Find words containing vowels 'aeiou' in that order: \n"
for word in datafile:
word = cleanWord(word)
if len(word)<=6:
continue
vowelStr=getVowelsInword(word)
if vowelStr=="aeiou":
print word
Written on January 13, 2013
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK