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"

Recommended Answers

All 3 Replies

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 )

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'

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 .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.