获取字典mydict的key,value,item
- mydict.keys()
- mydict.values()
- mydict.items() 返回键值对 元组
删除字典mydict中某个元素:
- del mydict[key]
- mydict.pop(key,None)
统计字符个数
str = "abc"
k_v_dict = {}
for c in str:
k_v_dict.get(c,0) + 1#若字典中没有该键,为该键赋默认值0
#{a:1,b:1,c:1}
str = "abc"
k_v_dict = {}
for c in str:
k_v_dict.get(c,0) + 1#若字典中没有该键,为该键赋默认值0
#{a:1,b:1,c:1}