i have data list of scores each of various users. following code finds maximum value of last 3 scores user (sorted user lowest score shown first), , print out:
dlist = {c:max(d[c][-3:]) c in d} #max each user last 3 itmlist = sorted(dlist.items(), key=lambda x: x[1]) #sort items z in itmlist: print('{}: {} '.format(z[0], z[1])) #print user-by-user
i'm trying modify use sum(l)/len(l)
in order find average value of last 3 scores each user, , sort print lowest user averages in order, have hit dead end.
can point me in right direction?
--
edit:
this code used generate list. using text file containing data containing scores in format like:
bob:2
john:7
this read using this:
[view post history]
the question bit unclear, have made assumptions, tell me if wrong somewhere?
d = {"bob":[1,2,3,4], "anmol":[5,4,3,2,1], "jhon":[3,2,1,8,7]} new_sorted_list = sorted(d.keys(), key=lambda x: sum(d[x][-3:])/3) print new_sorted_list >>> ['anmol', 'bob', 'jhon'] record in new_sorted_list: print record+" : "+str(sum(d[record][-3:])/3.0) >>> anmol : 2.0 bob : 3.0 jhon : 5.33333333333