CheckIO: Count “Striped words”

I learned re.split(pattern, text) in CheckIO Count Striped words question.

*Striped word is a word its alphabets sequenced vowels or consonants alternately.

import string
import re

DELIMITER = string.punctuation + string.whitespace

def split_text(text, delimiters):
    pattern = "|".join(re.escape(d) for d in delimiters)
    return re.split(pattern, text)

def is_striped(word):
    if not word:
        return False
    compared = word[1:]
    for c1, c2 in zip(word, compared):
        if c1.upper() in VOWELS and c2.upper() in VOWELS \
           or c1.upper() in CONSONANTS and c2.upper() in CONSONANTS:
           return False
    return True

text == "My name is ..."
splitted = list(filter(lambda w: w and len(w) > 1 and'\d', w) is None,
                           split_text(text, DELIMITER)))
print(len([w for w in splitted if is_striped(w)]))


Leave a Reply

Your email address will not be published. Required fields are marked *