Selecting the first consonant in a word (following a number of vowels)

lenawb

Hi I am trying to make a pig-latin translator and a problem arose when I tried to deal with words beginning in vowels. The aim would be that, for words with vowels at the beginning, the suffix would be the first consonant in the word + "ay" (Rather than the first letter in the word + "ay") For example 'ear' would be 'ear-ray' rather than 'ar-eay'

However, I am struggling to find a way to do this.

This i what I have so far: (it is taken from a larger section of code)

elif word[0]=="a" or word[0]=="e" or word[0]=="i" or word[0]=="o" or word[0]=="u":
    for letter in word[1:]:
      while consonantfound == False:
        if letter!="a" and letter!="e" and letter!="i" and letter!="o" and letter!="u":
          consonantfound = True
          consonant = letter
    suffix = consonant + "ay"
    newWord = i + "-" + suffix

This made the program just fail to produce an output and continue to run.

I feel like the problem is to do with the sequence of loops but I have experimented with it and no solution presented itself. It could also be something else that I am not aware of.

Do you have a suggestions as to how to make it work?

Any help will be much appreciated.

StubbyAngel9

Try this:

VOWELS = ('a', 'e', 'i', 'o', 'u')

def first_consonant(word):
    for letter in word:
        if letter.lower() not in VOWELS:
            return letter

def pig_latin(word):
    return '%s-%say' % (word, first_consonant(word) or word[0])

It tries to find the first consonant in a word and appends ay to the end. If it's not present then it defers to the first letter of the word (I don't know if this is correct, but you can adapt it to your needs).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

method evaluating a word with vowels in alphabetical order

From Dev

Perl word disenvoweling: removing all vowels except the first and last

From Dev

Finding out if half the letters in a word are vowels

From Dev

Remove vowels except if it the starting of the word

From Dev

Count the number of vowels in an array in PHP

From Dev

Is there a better way to check for vowels in the first position of a word?

From Dev

counting the number of vowels in a word in a string

From Dev

Greatest number of consecutive vowels

From Dev

Count vowels in a word

From Dev

regexp for word "port" following space and number

From Dev

Count the number of vowels and print them in a manner that string having more vowels come first

From Dev

Method miscalculates number of vowels

From Dev

How to add Hebrew vowels in Word 2010

From Dev

Count the vowels in a string including Y if its followed by a consonant

From Dev

Consonant counting program not returning number of consonants

From Dev

Recursive function in a character array for finding a consonant in the first 3 elements in the array

From Dev

Count the number of vowels in an array in PHP

From Dev

python vowels counter in each word

From Dev

Check if a word starts with a Vowel or a Consonant

From Dev

javascript regexp help selecting a word but no the first character

From Dev

Program to print a word with most number of vowels

From Dev

Selecting first alphabet in a word document

From Dev

Replace vowels in string with word "oodle" without replacing the vowels in "oodle"

From Dev

Return a boolean if the first letter is a consonant or not

From Dev

How to extract consonant / vowels groups from a word ?

From Dev

Word 2010 Number of pages without first page

From Dev

In Python, how do I check the first two letters of each word in a sentence to see if they have vowels in them?

From Dev

Eliminating Vowels in order from a word C++

From Dev

Removing ending vowels from a word

Related Related

  1. 1

    method evaluating a word with vowels in alphabetical order

  2. 2

    Perl word disenvoweling: removing all vowels except the first and last

  3. 3

    Finding out if half the letters in a word are vowels

  4. 4

    Remove vowels except if it the starting of the word

  5. 5

    Count the number of vowels in an array in PHP

  6. 6

    Is there a better way to check for vowels in the first position of a word?

  7. 7

    counting the number of vowels in a word in a string

  8. 8

    Greatest number of consecutive vowels

  9. 9

    Count vowels in a word

  10. 10

    regexp for word "port" following space and number

  11. 11

    Count the number of vowels and print them in a manner that string having more vowels come first

  12. 12

    Method miscalculates number of vowels

  13. 13

    How to add Hebrew vowels in Word 2010

  14. 14

    Count the vowels in a string including Y if its followed by a consonant

  15. 15

    Consonant counting program not returning number of consonants

  16. 16

    Recursive function in a character array for finding a consonant in the first 3 elements in the array

  17. 17

    Count the number of vowels in an array in PHP

  18. 18

    python vowels counter in each word

  19. 19

    Check if a word starts with a Vowel or a Consonant

  20. 20

    javascript regexp help selecting a word but no the first character

  21. 21

    Program to print a word with most number of vowels

  22. 22

    Selecting first alphabet in a word document

  23. 23

    Replace vowels in string with word "oodle" without replacing the vowels in "oodle"

  24. 24

    Return a boolean if the first letter is a consonant or not

  25. 25

    How to extract consonant / vowels groups from a word ?

  26. 26

    Word 2010 Number of pages without first page

  27. 27

    In Python, how do I check the first two letters of each word in a sentence to see if they have vowels in them?

  28. 28

    Eliminating Vowels in order from a word C++

  29. 29

    Removing ending vowels from a word

HotTag

Archive