Python checkio "Striped Words"解决方案

来源:互联网 发布:免费网页数据采集器 编辑:程序博客网 时间:2024/06/05 14:32
VOWELS = "AEIOUY"CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"def checkio(text):    import string    text = ''.join([' ' if char in string.punctuation else char for char in text ])    words = text.split()    return sum([checkword(word) if word.isalpha() else 0 for word in words])def checkword(word):    if len(word) == 1 :return 0    return 1 if all([True if (word[i].upper() in VOWELS and word[i + 1].upper() in CONSONANTS) or (word[i + 1].upper() in VOWELS and word[i].upper() in CONSONANTS) else False for i in range(len(word)-1)]) else 0



原创粉丝点击