By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,822 Members | 1,053 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,822 IT Pros & Developers. It's quick & easy.

Python function character proportion

P: 1
How do I find word(s) in string that has the lowest vowel proportion? For example the word 'love' is 2/4 = 0.5.

Example :

Expand|Select|Wrap|Line Numbers
  1. text = "music and rythm"
The result will be

Expand|Select|Wrap|Line Numbers
  1. ["rythm"]
Expand|Select|Wrap|Line Numbers
  1. text = "least great and good"
The result will be:

Expand|Select|Wrap|Line Numbers
  1. ["least","great"]
Apr 18 '13 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 626
Iterate/look at each letter. If it is a vowel then add one to the vowel counter, and if not then add one to the consonant counter. Divide the vowels by the consonants, remember to convert to float if using Python 2.X, and append to a list of lists as [result_of_division, word]. You can sort the list in ascending or descending to find the greatest or the least.
Apr 18 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.