求输入的字符串(zfc=('the' , 'Wu' , 'eru' , 'Why'))中首字母大写的单词的个数。
# encoding: utf-8
import re
zfc=['the' , 'Wu' , 'eru' , 'Why']
result = len(list(filter(lambda(x): re.match(r'[A-Z].*', x) , zfc)))
print(result)
2
x=0
zfc=['the','Wu','eru','Why']
for i in zfc:
if i.istitle()==True:
x+=1
print(x)
这样好像更简单一点