python - Sorting list by values -


i'm trying sort dictionary values code has been erroring. have 3 files consisting of scores (in format "bob:4", line breaks between each score.

for k in d.keys():     nlist = d[k][-3:]     v in nlist:         nlist2 = max(nlist)     sortd = sorted(nlist2.items(), key=lambda x: x[1])     print('{}: {} '.format(k, sortd)) 

this resulted in error "attributeerror: 'list' object has no attribute 'items'".

what causing error?

for revised question could:

nlist2 = {k:max(d[k][-3:]) k in d} sortd = sorted(nlist2.items(), key=lambda x: x[1]) in sortd:   print('{}: {} '.format(a[0], a[1])) 

or use -x[1] if want highest first


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -