0

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.

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

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.

Edited by pyTony: n/a

0

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 :)

0

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.

Edited by pyTony: n/a

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.