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

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -