标签:car local 信息 出现 print 列表 class style 个数
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)
标签:car local 信息 出现 print 列表 class style 个数
原文地址:https://www.cnblogs.com/kenD/p/9426814.html