fd = open('Class1.txt')
lines = [line.strip() for line in fd]
s = {}
for line in lines:
splitted = [i for i in line.split(',')]
key = splitted[0]
s[key] = [int(n) for n in splitted[1:]]
def average():
avg_mark = lambda name:sum(s[name])/len(s[name])
for i in sorted(s.keys(),key=avg_mark,reverse=True):
print (i,avg_mark(i),"\n")
average()
average()
average()
Right so i've changed the code so then it just does the average but when i run it it doesn't stop can anyone help me. thanks
I need help shortening this piece of code because it is too long. I need to do this for three other classes as well and don't want it to be lines of code and was just wandering if it could be shortened.
Thanks