ss="i love youo your youu loce"
dictAreas={}
for i in ss:dictAreas[i]=dictAreas.get(i,0)+1 #get可以默认返回0 找不到就返回0
print(dictAreas)
重点 字典排序
print(dictAreas.items())#返回双元素 元祖的列表print(dictAreas.keys())#键链表print(dictAreas.values())#值链表dictAreas={
"china":9001,"russia":9090}for k,v in dictAreas.items():print(k,v)
ls=sorted(dictAreas)for country in ls :print(country,dictAreas[country])#字典排序
lsVK=[(v,k)for k,v in dictAreas.items()]
lsVK.sort()
lsKV=[(k,v)for v,k in lsVK]print(lsKV)dictAreas=dict(lsKV)
dictAreas2={
"djkd":333,"china":9000}
dictAreas.update(dictAreas2)#如果存在就跟新 不存在就自动加入新的元素print(dictAreas)new=dict(dictAreas,**dictAreas2)#dict生成一个新的print(new)