cars = ["鲁A32444","鲁B12333","京B8989M","黑C49678","黑C46555","沪B25041"]
locals = {"沪":"上海","黑":"黑龙江","鲁":"山东","鄂":"湖北","湖":"湖南"}
lst = []
dic ={}
for i in cars:
lst.append(i[0])
for j in lst:
if j in locals.keys():
dic.setdefault(locals[j],lst.count(j))
print(dic)
======================================================================================
cars = ["鲁A32444","鲁B12333","京B8989M","黑C49678","黑C46555","沪B25041"]
locals = {"沪":"上海","黑":"黑龙江","鲁":"山东","鄂":"湖北","湖":"湖南"}
result = {}
for car in cars:
first_name = car [0]
if first_name in locals.keys():
location = locals[first_name]
if result.get(location) == None:
result[location] = 1
else:
result[location] = result[location] + 1
print(result)