统计名字列表中,各名字的首字母在名字列表中出现的次数

name_list=['foster',"janet",'jessus','david']
count_dict={}
for i in name_list:
    count_dict[i]="".join(name_list).count(i[0])

print count_dict
>>> def countfist(a):
...     res = {}
...     for i in a:
...         res[i] = "".join(a).count(i[0])
...     return res
...
>>> countfist(new_mystr)
{'and': 3, 'world': 1, 'itcastcpp': 2, 'itcast': 2, 'hello': 1}
>>>
>>> name_list=['foster',"janet",'jessus','david']
>>> countfist(name_list)
{'david': 2, 'foster': 1, 'janet': 2, 'jessus': 2}
>>>

分享文章:统计名字列表中,各名字的首字母在名字列表中出现的次数
网页链接:http://www.csruizhi.cn/article/iigihs.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 手机网站制作 成都网站建设推广 宜宾网站设计 营销型网站建设 品牌网站建设 上市集团网站建设 广安网站设计 定制网站建设多少钱 成都网站建设公司 成都网站设计 专业网站设计 高端网站设计 成都网站建设 成都网站制作 成都网站建设公司 成都响应式网站建设公司 成都定制网站建设 成都定制网站建设 网站建设公司 营销网站建设 重庆手机网站建设 重庆网站建设