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
AI 代码解读
>>> 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}
>>>
AI 代码解读
>>> name_list=['foster',"janet",'jessus','david']
>>> countfist(name_list)
{'david': 2, 'foster': 1, 'janet': 2, 'jessus': 2}
>>>
AI 代码解读
本文转自 知止内明 51CTO博客,原文链接:http://blog.51cto.com/357712148/2072736,如需转载请自行联系原作者