python面试编程题
1:已知字符串 str= 'skdaskerkjsalkj',请统计该字符串中各字母出现的次数
思路是:用字典
str='skdaskerkjsalkj'
a=dict()
for i in str:
if i not in a.keys():
a[i]=1
else:
a[i]=a[i]+1
print(a)
1:已知字符串 str= 'skdaskerkjsalkj',请统计该字符串中各字母出现的次数
思路是:用字典
str='skdaskerkjsalkj'
a=dict()
for i in str:
if i not in a.keys():
a[i]=1
else:
a[i]=a[i]+1
print(a)