1、假设员工的姓均为姓名中的第1个字符。编写程序,统计下列列表中各姓氏所含的人数。 测试示例如下: 列表如下: incomeList = [ ['10932','张珊',15000.00 ,4000.00 ,2300.00 ,980.00 ,300.00 ,1000.00], ['10933','李思',12000.00 ,5000.00 ,2600.00 ,890.00 ,400.00 ,2000.00], ['10934','王武',10100.00 ,2000.00 ,2500.00 ,860.00 ,500.00 ,1500.00], ['10935','赵柳',10050.00 ,1000.00 ,2700.00 ,1080.00 ,300.00 ,2000.00], ['10936','钱棋',10200.00 ,2000.00 ,2400.00 ,1000.00 ,600.00 ,1000.00], ['10941','张明',13600.00 ,4000.00 ,2100.00 ,680.00 ,300.00 ,1000.00], ['10942','赵敏',13200.00 ,2500.00 ,2300.00 ,670.00 ,400.00 ,3000.00], ['10945','王红',13600.00 ,2600.00 ,2030.00 ,560.00 ,400.00 ,2000.00], ['10946','李萧',12500.00 ,2800.00 ,2400.00 ,420.00 ,500.00 ,1500.00], ['10947','孙科',12000.00 ,3500.00 ,2030.00 ,880.00 ,300.00 ,1000.00], ['10948','刘利',14200.00 ,2500.00 ,2020.00 ,900.00 ,400.00 ,2000.00] ]
时间: 2023-07-02 10:12:20 浏览: 136
以下是Python代码实现:
```
incomeList = [
['10932', '张珊', 15000.00, 4000.00, 2300.00, 980.00, 300.00, 1000.00],
['10933', '李思', 12000.00, 5000.00, 2600.00, 890.00, 400.00, 2000.00],
['10934', '王武', 10100.00, 2000.00, 2500.00, 860.00, 500.00, 1500.00],
['10935', '赵柳', 10050.00, 1000.00, 2700.00, 1080.00, 300.00, 2000.00],
['10936', '钱棋', 10200.00, 2000.00, 2400.00, 1000.00, 600.00, 1000.00],
['10941', '张明', 13600.00, 4000.00, 2100.00, 680.00, 300.00, 1000.00],
['10942', '赵敏', 13200.00, 2500.00, 2300.00, 670.00, 400.00, 3000.00],
['10945', '王红', 13600.00, 2600.00, 2030.00, 560.00, 400.00, 2000.00],
['10946', '李萧', 12500.00, 2800.00, 2400.00, 420.00, 500.00, 1500.00],
['10947', '孙科', 12000.00, 3500.00, 2030.00, 880.00, 300.00, 1000.00],
['10948', '刘利', 14200.00, 2500.00, 2020.00, 900.00, 400.00, 2000.00]
]
# 定义一个字典,用于存储姓氏和对应的人数
count_dict = {}
for item in incomeList:
surname = item[1][0] # 取出姓氏
if surname in count_dict:
count_dict[surname] += 1 # 已经存在,则加1
else:
count_dict[surname] = 1 # 不存在,则设为1
# 输出结果
for surname, count in count_dict.items():
print(f"{surname}姓氏有{count}人")
```
输出结果为:
```
张姓氏有2人
李姓氏有2人
王姓氏有2人
赵姓氏有2人
钱姓氏有1人
孙姓氏有1人
刘姓氏有1人
```
阅读全文