求一个字符串中每个字符出现的次数
string = input('请输入一串字符串:')
str_dict = {}
for j in string:
if str_dict.get(j):
str_dict[j] += 1
else:
str_dict[j] = 1
print(str_dict)
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
string = input('请输入一串字符串:')
str_dict = {}
for j in string:
if str_dict.get(j):
str_dict[j] += 1
else:
str_dict[j] = 1
print(str_dict)
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
评论已关闭