for line_str in dict_file:
line_str = line_str.strip().lower()
line_count_int = 0
for i in line_str:
a_count = line_str.count('a')
e_count = line_str.count('e')
i_count = line_str.count('i')
o_count = line_str.count('o')
u_count = line_str.count('u')
if a_count == 1 and e_count == 1\
and i_count == 1 and o_count == 1 and u_count == 1:
print(line_str)
line_count_int += 1
else:
line_count_int += 1
Trying to find specific order of vowels in words
Page 1 of 16 Replies - 2355 Views - Last Post: 11 February 2016 - 07:10 AM
#1
Trying to find specific order of vowels in words
Posted 10 February 2016 - 01:36 PM
The overall goal is to find words that contain one of each vowel ('a','e','i','o', 'u'), as well as in the order that the vowels are listed. So far I am able to locate words that contain one of each vowel, but I am completely unsure on how to locate that specific order of vowels. Any type of hint or advice would be appreciated!
Replies To: Trying to find specific order of vowels in words
#2
Re: Trying to find specific order of vowels in words
Posted 10 February 2016 - 01:47 PM
Look into the index() method on strings. It will give you the index (location) of the specified character(s) within a string.
#3
Re: Trying to find specific order of vowels in words
Posted 10 February 2016 - 01:56 PM
#4
Re: Trying to find specific order of vowels in words
Posted 11 February 2016 - 05:16 AM
Why don't you consider the letter 'y a vowel?
In my language it is!
In my language it is!
#5
Re: Trying to find specific order of vowels in words
Posted 11 February 2016 - 05:23 AM
Here is a suggestion for an algorithm:
Initialize an empty result list.
Go through the word letter by letter.
Upon finding a vowel, add the vowel to the result list.
When the word is fully analysed, compare the result list with a target list (= ['a', 'e', 'i', 'o', 'u', 'y'])
You can optimize by breaking away as soon as the result list deviates from the target list.
Initialize an empty result list.
Go through the word letter by letter.
Upon finding a vowel, add the vowel to the result list.
When the word is fully analysed, compare the result list with a target list (= ['a', 'e', 'i', 'o', 'u', 'y'])
You can optimize by breaking away as soon as the result list deviates from the target list.
This post has been edited by DK3250: 11 February 2016 - 05:24 AM
#6
Re: Trying to find specific order of vowels in words
Posted 11 February 2016 - 05:56 AM
With that approach, going through the word letter by letter, I think I would build a string and just compare it to "aeiou", aborting when the length reaches 5.
I was thinking of something a little messier, something like:
but it needs jiggling if any value is -1. Well, only if the search for 'a' is -1.
Edited: Actually, it is find() rather than index() that returns -1. index() raises a ValueError if not found.
I was thinking of something a little messier, something like:
if word.index('a') < word.index('e') < word.index('i') etc:
but it needs jiggling if any value is -1. Well, only if the search for 'a' is -1.
Edited: Actually, it is find() rather than index() that returns -1. index() raises a ValueError if not found.
#7
Re: Trying to find specific order of vowels in words
Posted 11 February 2016 - 07:10 AM
From Wikipedia:
These letters are vowels in English:
A, E, I, O, U, and sometimes Y
The letter Y can be a vowel (as in the words "cry", "sky", "fly" or "why"), or it can be a consonant (as in "yellow", "yacht", "yam" or "yesterday").
So, when 'y' is at the end of a word it will probably be counted as a vowel; and as you search for words where 'y' actually is in the end (if at all), you should include 'y' - at least as a possibility...
These letters are vowels in English:
A, E, I, O, U, and sometimes Y
The letter Y can be a vowel (as in the words "cry", "sky", "fly" or "why"), or it can be a consonant (as in "yellow", "yacht", "yam" or "yesterday").
So, when 'y' is at the end of a word it will probably be counted as a vowel; and as you search for words where 'y' actually is in the end (if at all), you should include 'y' - at least as a possibility...
Page 1 of 1

New Topic/Question
Reply


MultiQuote




|