列表 ls 中存储了我国 39 所 985 高校所对应的学校类型,请以这个列表为数据变量,编写 代码,统计输出各类型的数量,要求按类别字母顺序输出。【样例输入】 无 【样例输出】 Agricultural and Forestry 2 Comprehensive 20 Military 1 Nationalities 1 Normal 2 Polytechnic 13
时间: 2023-06-16 07:07:20 浏览: 159
```python
ls = ['Comprehensive', 'Polytechnic', 'Normal', 'Nationalities', 'Agricultural and Forestry', 'Military', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal', 'Comprehensive', 'Polytechnic', 'Normal']
type_dict = {}
for t in sorted(set(ls)):
type_dict[t] = ls.count(t)
for k, v in type_dict.items():
print(k, v)
```
输出结果为:
```
Agricultural and Forestry 2
Comprehensive 10
Military 1
Nationalities 1
Normal 10
Polytechnic 15
```
阅读全文