str_one ='hello world'
dict_one = {}
for i in str_one:
dict_one[i] = str_one.count(i)
print(dict_one)
结果: {'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}
str_one ='hello world'
dict_one = {}
for i in str_one:
dict_one[i] = str_one.count(i)
print(dict_one)
结果: {'h': 1, 'e': 1, 'l': 3, 'o': 2, ' ': 1, 'w': 1, 'r': 1, 'd': 1}
本文标题:字典只添加值,键从哪里来的?
本文链接:https://www.haomeiwen.com/subject/eghwixtx.html
网友评论