option= input("alphabetically(a), high to low(b)")
if option == "a":
with open('Class4.txt', 'r') as r:
for line in sorted(r):
print(line)
elif option == "b":
def score(line):
return int(line.split(',')[1])
with open('Class4.txt', 'r') as r:
for line in sorted(r, key=score, reverse=True):
print(line)
I was able to display aplhabetically but was not able to display high to low the file class 4 contains variable name and score
ab 9
z 4
b 6
a10