1.车牌区域划分, 现给出以下车牌. 根据车牌的信息, 分析出各省的车牌持有量.
cars =["鲁A32444","鲁B12333","京B8989M","黑C49678","黑C46555","沪B25041"] locals={'沪':"上海","黑":"黑龙江","鲁":"山东","鄂":"湖北","湘":"湖南","京":"北京"} li=[] cars_locals={} for el in cars: li.append(locals[el[0]])###li:山东,北京.... cars_locals[locals[el[0]]]=cars_locals.get(locals[el[0]],0)+1 ##get换成setdefault也可以 print(cars_locals)
2.冒泡排序
li=[77,2,965,112,56,97,87,256] j=0 while j < len(li)-1: for i in range(len(li)-1-j): if li[i] > li[i+1]: li[i], li[i+1] = li[i+1], li[i] j +=1 print(li)
3.完成彩票36选7的功能. 从36个数中随机的产生7个数. 最终获取到7个不重复的数据作为最终的开奖结果.
from random import randint s=set() while len(s)<7 : i=randint(1, 36) s.add(i) print(s)