python 3.x - count the number of words in a string separated by spaces and/or punctuation marks -


can please . want create program can count number of words in string separated spaces and/or punctuation marks. should count words vowels , consonants alternating. word can not have 2 consecutive vowels or consonants. single letter words not counted. ignore in file not vowel or constant. replace not in alphabet single space. case sensitivity of each letter not matter.

alphabet use vowels -- e o u y consonants -- b c d f g h j k l m n p q r s t v w x z

input: string eg "hello there great new world"

output: number of desired words found in input string above. eg 1

sample:

"welcome radix!!!" == 2 (to radix)

"everybody, trying out." == 2 (everybody for)

"hello there great new world" == 1 (new)

"mary,had,a,little,lamb" == 2 (mary had)

this homework, isn't it?

try regular expression:

\b[aeiouy]?([bcdfghjklmnpqrstvwxz][aeiouy])*[bcdfghjklmnpqrstvwxz]?\b 

it find words alternating vowels/consonants. beware, pass single-letter words well, filter them out subsequently. , run ignore-case flag.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -