为了账号安全,请及时绑定邮箱和手机立即绑定

有一个名单表,左边是名字,右边是名字含义

有一个名单表,左边是名字,右边是名字含义

catspeake 2023-04-02 18:14:05
先用文本分割,把名单表变成[{'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

查看完整回答
反对 回复 2023-04-05
  • 1 回答
  • 0 关注
  • 109 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信