MeowalsoMeow

university_enrollment_stage4

Jun 30th, 2021 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. choices = 3
  2. max_wanted = int(input())
  3. data = []
  4. with open('C:/Users/linyu/Downloads/applicant_list.txt') as f:
  5. for line in f:
  6. data.append(line.split())
  7. #print(data)
  8. sorted_data = sorted(data, key=lambda x: (-float(x[2]), x[0]))
  9. print(sorted_data)
  10. #biotech = [sorted_data[_i][0] + ' ' + sorted_data[_i][1] for _i in range(max_wanted) if sorted_data[_i][3] == 'Biotech']
  11. def students_for_major(major):
  12. global choices
  13. global sorted_data
  14. global max_wanted
  15. major_li = []
  16. for c in range(choices):
  17. if len(major_li) >= max_wanted:
  18. break
  19. if len(major_li) < max_wanted:
  20. # print('<')
  21. # print(sorted_data[0][c])
  22. major_li.extend([sorted_data[_i][0] + ' ' + sorted_data[_i][1] for _i in range(len(sorted_data)) if sorted_data[_i][c + 3] == major if len(major_li) < max_wanted])
  23. # print(sorted_data[1][c + 3], sorted_data[1][c + 1 + 3], sorted_data[1][c + 2 + 3])
  24. return major_li
  25. # I forgot to add 2 to c to get the correct digit of list and wasted a long time
  26.  
  27. #need to deduct enrolled students
  28. biotech = students_for_major('Biotech')
  29. chemistry = students_for_major('Chemistry')
  30. engineering = students_for_major('Engineering')
  31. mathematics = students_for_major('Mathematics')
  32. physics = students_for_major('Physics')
  33.  
  34.  
  35.  
  36. # biotech = [sorted_data[_i][0] +' ' + sorted_data[_i][1] for _i in range(max_wanted) if sorted_data[_i][3] == 'Engineering']
  37. print(engineering, chemistry,biotech,mathematics,physics, sep='\n')
Add Comment
Please, Sign In to add comment