In my previous question, I found out how to drag some of my co - worker's scores together in a dictionary in the post Reading data separated by colon per line in Python.
Now, if I want to arrange the dictionary so that the keys are in order of name, so Adam
, Dave
and Jack
's scores would appear in that order.
I have used the method below:
sorted(self.docs_info.items)
But that returns nothing. I also want it to be returned to the IDLE in the format
Adam 12 34
Dave 25 23
Jack 13
I tried to use the pprint
method, but that didn't work either.
How can I fix this?
My previous code (finished) appeared like this:
from collections import defaultdict
d = defaultdict(list)
with open('guesses.txt') as f:
for line in f:
name,val = line.split(":")
d[name].append(int(val))
With Credit to Padraic Cunningham and Antti Haapala!