Python function character proportion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Jenner
    New Member
    • Apr 2013
    • 1

    Python function character proportion

    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 :

    Code:
    text = "music and rythm"
    The result will be

    Code:
    ["rythm"]
    Code:
    text = "least great and good"
    The result will be:

    Code:
    ["least","great"]
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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_divis ion, word]. You can sort the list in ascending or descending to find the greatest or the least.

    Comment

    Working...