Skip to content

Instantly share code, notes, and snippets.

@muellmatto
Created August 11, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muellmatto/f81ddfdf0a8ab88bd9173b8d3a7bda12 to your computer and use it in GitHub Desktop.
Save muellmatto/f81ddfdf0a8ab88bd9173b8d3a7bda12 to your computer and use it in GitHub Desktop.
def get_course(courses, name):
for c in courses:
if c['name'] == name:
print("\n".join(c['students']))
def gen_courses(raw_file):
courses = []
students = []
course_name = None
for line in raw_file:
if line.startswith("Kurs:"):
#new cours
if course_name:
# add and reset
# sort students
students.sort()
courses.append({"name": course_name, "students": students})
students = []
print(f"added {course_name}")
course_name = line.split(";")[0].split(":")[1].strip()
print(f"found {course_name}")
elif line[0].isdigit():
last_name, first_name = line.split(";")[1].split(",")
students.append(f"{first_name.strip()} {last_name.strip()}")
if course_name:
# add last course
courses.append({"name": course_name, "students": students})
print(f"added {course_name}")
return courses
def read_file(path):
with open("Kurse Q2.csv", "r") as csv:
return csv.readlines()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment