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 12:05:32 浏览: 202
可以通过遍历列表中的每个元素,获取姓名并统计每个姓氏的人数。具体实现如下:
```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]
]
name_count = {}
for person in incomeList:
first_name = person[1][0]
if first_name in name_count:
name_count[first_name] += 1
else:
name_count[first_name] = 1
print(name_count)
```
运行结果如下:
```
{'张': 2, '李': 2, '王': 2, '赵': 2, '钱': 1, '孙': 1, '刘': 1}
```
可以看到,该程序统计了每个姓氏的人数,并将结果存储在一个字典中,字典的键为姓氏的第一个字符,值为该姓氏的人数。
阅读全文