learn.py 798 B

1234567891011121314151617181920212223242526
  1. from collections import defaultdict
  2. import re
  3. with open('./static/年级学院专业.txt','r') as f:
  4. academys = defaultdict(dict)
  5. for line in f.readlines():
  6. data = line.split('@')
  7. academy = data[1]
  8. major = data[2].strip()
  9. if major not in academys[academy]:
  10. academys[academy][major] = []
  11. s = re.sub("\d+级",'',data[3].strip())
  12. s = re.sub("\d+",'',s)
  13. academys[academy][major].append(s)
  14. else:
  15. s = re.sub("\d+级",'',data[3].strip())
  16. s = re.sub("\d+",'',s)
  17. academys[academy][major].append(s)
  18. for academy_ in academys.keys():
  19. for key,item in academys[academy_].items():
  20. academys[academy_][key] = set(item)
  21. print('学院数量:',len(academys.keys()))
  22. for academy in academys.keys():
  23. print(academy,'有 {} 个专业'.format(len(academys[academy].keys())))