老男孩Python全栈学习 S9 日常作业 007

时间:2024-04-29 19:07:52

1、把列表中所有姓周的人的信息删掉

lst = ['周老二', '周星星', '麻花藤', '周扒皮']
lst = ['周老二', '周星星', '麻花藤', '周扒皮']
lst2 = []
for i in range(len(lst)):
if not lst[i].startswith('周'):
lst2.append(lst[i])
lst = lst2

2、车牌区域划分, 现给出以下车牌. 根据车牌的信息, 分析出各省的车牌持有量.

  • cars = ['鲁A32444','鲁B12333','京B8989M','黑C49678','黑C46555','沪 B25041']
  • locals = {'沪':'上海', '黑':'黑龙江', '鲁':'山东', '鄂':'湖北', '湘':'湖南', '京': '北京'}
  • 结果: {'山东': 2, '北京': 1, '黑龙江': 2, '上海': 1}
cars = ['鲁A32444','鲁B12333','京B8989M','黑C49678','黑C46555','沪 B25041']
locals = {'沪':'上海', '黑':'黑龙江', '鲁':'山东', '鄂':'湖北', '湘':'湖南'}
dic = {}
for i in locals:
dic[i] = 0
for i in cars:
if i.startswith('黑'):
dic['黑'] = dic['黑']+1
elif i.startswith('湘'):
dic['湘'] = dic['湘'] + 1
elif i.startswith('沪'):
dic['沪'] = dic['沪'] + 1
elif i.startswith('鄂'):
dic['鄂'] = dic['鄂'] + 1
elif i.startswith('鲁'):
dic['鲁'] = dic['鲁'] + 1
else:
continue

3、干掉主播. 现有如下主播收益信息: zhubo = {'卢本伟':522000, '冯提莫':189999, '金老板': 99999, '吴老板': 250000, 'alex': 126}

  1. 计算主播平均收益值
  2. 干掉收益小于平均值的主播
  3. 干掉卢本伟
zhubo = {'卢本伟':522000, '冯提莫':189999, '金老板': 99999, '吴老板': 250000, 'alex': 126}
List = []
for i in zhubo.values():
List.append(i) money = 0
ave = 0
for i in List:
money += i
ave += 1
Ave = money/ave dic = {}
for i in zhubo:
if zhubo[i] >= Ave:
dic[i] = zhubo[i] dic.pop('卢本伟')