Created
August 11, 2020 19:49
-
-
Save muellmatto/f81ddfdf0a8ab88bd9173b8d3a7bda12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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