Skip to content

Instantly share code, notes, and snippets.

@jiobu1
Created April 23, 2021 19:26
Show Gist options
  • Save jiobu1/4d766958f5178dc83f655a4af9e6167c to your computer and use it in GitHub Desktop.
Save jiobu1/4d766958f5178dc83f655a4af9e6167c to your computer and use it in GitHub Desktop.
parse grades
def parse_grades(grades_string):
GRADES = ['PK', 'K', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', 'Ungraded']
# Remove & for grades list
grades_string = grades_string.replace(' &', ',')
# Grades list - will add to separated grade string to grades
grades = []
# split strings based on ','
string_list = grades_string.split(',')
# look for sections of list with '-'
dash = "-"
for i in range(len(string_list)):
clean_string = string_list[i].strip()
if dash in clean_string:
# split using '-', loop and add to grades variable
start_grade, end_grade = clean_string.split(dash)
grades += GRADES[GRADES.index(start_grade) : GRADES.index(end_grade)+ 1]
else:
# add string to grades
grades.append(clean_string)
return grades
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment