Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- choices = 3
- max_wanted = int(input())
- data = []
- with open('C:/Users/linyu/Downloads/applicant_list.txt') as f:
- for line in f:
- data.append(line.split())
- #print(data)
- sorted_data = sorted(data, key=lambda x: (-float(x[2]), x[0]))
- print(sorted_data)
- #biotech = [sorted_data[_i][0] + ' ' + sorted_data[_i][1] for _i in range(max_wanted) if sorted_data[_i][3] == 'Biotech']
- def students_for_major(major):
- global choices
- global sorted_data
- global max_wanted
- major_li = []
- for c in range(choices):
- if len(major_li) >= max_wanted:
- break
- if len(major_li) < max_wanted:
- # print('<')
- # print(sorted_data[0][c])
- 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])
- # print(sorted_data[1][c + 3], sorted_data[1][c + 1 + 3], sorted_data[1][c + 2 + 3])
- return major_li
- # I forgot to add 2 to c to get the correct digit of list and wasted a long time
- #need to deduct enrolled students
- biotech = students_for_major('Biotech')
- chemistry = students_for_major('Chemistry')
- engineering = students_for_major('Engineering')
- mathematics = students_for_major('Mathematics')
- physics = students_for_major('Physics')
- # biotech = [sorted_data[_i][0] +' ' + sorted_data[_i][1] for _i in range(max_wanted) if sorted_data[_i][3] == 'Engineering']
- print(engineering, chemistry,biotech,mathematics,physics, sep='\n')
Add Comment
Please, Sign In to add comment