统计一个字符串中各个字符个数

# 统计一个字符串中各个字符个数
#
# words="hello word"
# wordsCount={}
# for i in words:
#     if i!=" ":
#         wordsCount[i]=0
# for i in words:
#     if i != " ":
#         wordsCount[i] +=1
# print(wordsCount)

a = "hello"
b = dict.fromkeys(a, 0)
print(b)
print("b[o] :",b["o"])
# print(b)
for x in a:
    b[x]+=1
    # print(b[x])
print(b)

猜你喜欢

转载自www.cnblogs.com/gaoyuanyuan/p/9447976.html
今日推荐