练习:根据车牌信息,统计各省车牌持有量
Posted kend
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了练习:根据车牌信息,统计各省车牌持有量相关的知识,希望对你有一定的参考价值。
cars = ["鲁A32444","鲁B12333","京B8989M","黑C49555","沪B25041"]
locals = {"沪":"上海","黑":"黑龙江","鲁":"山东","京":"北京"}
结果:{"山东":2,"北京":1,"黑龙江":1,"上海":1}
cars = ["鲁A32444","鲁B12333","京B8989M","黑C49555","沪B25041"] locals = {"沪":"上海","黑":"黑龙江","鲁":"山东","京":"北京"} dic = {} names = [] for i in cars: value = locals[i[0]] #黑龙江 names.append(value) #[‘山东‘, ‘山东‘, ‘北京‘, ‘黑龙江‘, ‘上海‘] set1 = set(names) #{‘山东‘, ‘北京‘, ‘黑龙江‘, ‘上海‘} for j in set1: dic.update({j:names.count(j)}) ## 注意 统计列表中不同元素出现的个数 元素作为key 出现的次数是value print(dic)
以上是关于练习:根据车牌信息,统计各省车牌持有量的主要内容,如果未能解决你的问题,请参考以下文章
车牌区域划分,给出以下车牌,根据车牌信息,分析出各省的车牌持有量