统计名字列表中,各名字的首字母在名字列表中出现的次数-成都快上网建站

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

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}
>>>

分享标题:统计名字列表中,各名字的首字母在名字列表中出现的次数
URL标题:http://kswjz.com/article/iigihs.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流