先用文本分割,把名单表变成[{'name':'Aaron', 'meaning':'Enlightened'}, ...]然后统计名字以'C'开头,名字含义里包含's'的条目个数name_text='''Aaron EnlightenedAbbott FatherAbel BreathAbner Father of LightAbraham Exalted FatherAdam Man of EarthAddison Son of AdamAdler EagleAdley The JustAdrian, Adrien The Dark OneAedan, Aiden Born of FireAiken The OakenAlan, Allan Handsome OneAlastair Defender of MenAlbern Of Noble ValorAlbert Noble, BrightAlbion White or FairAlden Wise Guardian
1 回答
湖上湖
TA贡献2003条经验 获得超2个赞
name_meaning_dict = {}
count = 0
for line in name_text.splitlines():
parts = line.split()
name_meaning_dict['name'], name_meaning_dict['meaning'] = parts[0], parts[1:]
for n, m in name_meaning_dict:
if n.startswith('C') and m.find('s) >= 0:
count += 1
print count
添加回答
举报
0/150
提交
取消