擅长:python、mysql、java
<pre><code>def checkString(teststring):
'''To check for pattern: Consonant:Vowel and return true if pattern exists'''
const = "bcdfghjklmnpqrstvwyz"
vowels = "aeiou"
t_odd = teststring[::2].lower()
t_even = teststring[1::2].lower()
outcome = ["True" if x in const else "False" for x in t_odd ] + ["True" if y in vowels else "False" for y in t_even]
return all(item == "True" for item in outcome)
#Test
checkString("Bolelaaa")
checkString("bomelela")
</code></pre>
<p>在这个函数中,我使用列表理解来测试odd&;偶数字母分别对应辅音和元音列表。如果所有比较都为true,则函数返回true</p>