cars = ['鲁A32444','鲁B12333','京B8989M','黑C49678','黑C46555','沪 B25041']
locals = {'沪':'上海','黑':'黑龙江','鲁':'山东','鄂':'湖北','湘':'湖南','京':'北京'}
dic = {}
for key,value in locals.items():
count = 0
for i in cars:
if key == i[0]:
count += 1
if count > 0:
dic[value] = count
print(dic)
#第二种
dic = {}
for i in cars:
if locals[i[0]] not in dic:
dic[locals[i[0]]] = 1
else:
dic[locals[i[0]]] = dic[locals[i[0]]] +1
print(dic)
#第三种
dic = {}
for i in cars:
dic[locals[i[0]]] = dic.get(locals[i[0]],0) + 1
print(dic)