查找字典条目
统计句子“Life is short,we need Python.”中各字符出现的次数。
s='Life is short,we need Python.'
s=s.lower()
print(s)
dic={}
for a in s:
dic[a] = dic.get(a,0) + 1
for k in dic:
print(k,dic[k])
微信扫一扫
统计句子“Life is short,we need Python.”中各字符出现的次数。
s='Life is short,we need Python.'
s=s.lower()
print(s)
dic={}
for a in s:
dic[a] = dic.get(a,0) + 1
for k in dic:
print(k,dic[k])
相关推荐