I'm trying to sort a dictionary by values but my code has been erroring. I have three files consisting of scores (in the format "Bob:4", with line breaks between each score.
for k in d.keys(): nlist = d[k][-3:] for 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 is causing this error?
nlist? is it a list ?print(d)in before your for k loop to make sure you have what you think you have