Hey guys, before I begin, I'd like to specify that this is for a personal project that I am playing with, and not for work or school or anything of that ilk.

In Python, I am trying to define a function that will search a .txt file containing a large number of terms (just single words per line, no sentences) for words that are of a user-defined length, that do not contained a user-defined letter and contain only one vowel.

I am a bit mystified as to how I'd go about fulfilling these parameters.

Any explanation or advice would be appreciated.

Recommended Answers

All 3 Replies

Test first for length, then read characters, fail if no vowel found or if there is any other vowel after first vowel found.

As alternative you can make correct length word lowercase and strip all consonants, if only one wovel is left accept the original word.

1.Make a list of your vowels.
2.Read the text file
3. Read character per character
4.Check if the char is in the vowels.

Job done :)

Made the function and for your information it has one one line function, two and three variable initializations and one print with generator expression. The function I give here, I do not want to spoil your fun by sending the whole code:

def wovel_count(word, vowels):
    return sum(c in vowels for c in word)

Oh I did not implement the input part but hard coded them first in one variable.

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.