python不用函数如何统计个数
提问:python不用函数如何统计个数
#2、给出一个字符串,在程序中赋初值为一个句子,例如‘he threw three free throws‘,不使用函数情况下完成下面的功能:1) 求出字符列表中字符的个数(对于例句,输出26);2) 计算句子中各字符出现的频数(通过字典存储字符和频数)
网友回答:
不用函数,简单的程序参考
#coding:utf-8
s='he threw three free throws'
d={}
ct=0
for c in s:
ct+=1
if c in d:
d[c]+=1
else:
d[c]=1
print(ct)
print(d)