-4

On the Unix machines,there is a file /usr/dict/words that contains a list of English words,one per line.This file is used by spell-checking programs for example.
Write a python function which takes one argument,which is a word (as a string)and returns true if the word contains alternating vowels and consonants (i.e a consonant followed by a vowel followed by a consonant) Then write a short piece of code to read the above file and print out all the words like "banana" and "lever" but not words like "knock" and "print"

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Gribouillis
0

Very smart homework problem. Now let's see some effort on your part to solve it!

Hint ...

vowels = 'aeiouy'

word = 'polarity'

for letter in word:
    if letter in vowels:
        print( letter )

Edited by vegaseat: homework

0

Very smart homework problem. Now let's see some effort on your part to solve it!

Hint ...

vowels = 'aeiouy'

word = 'polarity'

for letter in word:
    if letter in vowels:
        print( letter )

I came up with this,but it does not carry out exactly what is required. Need some help to modify it. Thanks!

def check(k):
       d = ('a','e','i','o','u')
        first,second = 0,1
           if k(first) in d:
             if k(second) not in d
             first+=2
             second+=2
         return 'true'

Edited by vegaseat: added code tags

0

Here is another hint:

word = 'polarity'

even_letters = [word[i] for i in range(0, len(word), 2)]
odd_letters = [word[i] for i in range(1, len(word), 2)]

print(even_letters)
print(odd_letters)

Also note that on some linuxes, the dictionary is at /usr/share/dict/words .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.