Created
June 6, 2019 06:06
-
-
Save jmoy/2be26a7d616d487e0b36bbcc1d42a50e to your computer and use it in GitHub Desktop.
Session 1 in Python
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
with open("code/test2.txt") as fin: | |
sbj_counts = {} | |
for l in fin: | |
l = l.strip() | |
m = re.fullmatch(r"((?:\w|\.)+)\s+in\s+(\w+)",l) | |
if m: | |
degree,subject = m.group(1,2) | |
print(f"{degree} ({subject})") | |
if subject in sbj_counts: | |
sbj_counts[subject].add(degree) | |
else: | |
sbj_counts[subject] = {degree} | |
else: | |
print(l) | |
for subj in sorted(sbj_counts): | |
degrees = sorted(sbj_counts[subj]) | |
deglst = ', '.join(degrees) | |
was_were = "was" if len(degrees)==1 else "were" | |
print(f"{deglst} {was_were} awarded in {subj}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment