+ 1

Tuples and dict.

ok... beginning to hit too many roadblocks no matter how many extra practice I do. I have this working all the way through and as far as I can tell it should be doing exactly what is needed. I need my output to be this: 04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1 Except I Keep getting mine in random order despite sorting and everything else the numbers are right just wont sort. I get this.. 11 6 16 4 10 3 04 3 17 2 15 2 09 2 19 1 18 1 14 1 07 1 06 1 fname = input("Enter file name: ") fh = open(fname) count = dict() for handle in fh: if not handle.startswith("From "): continue #print(handle) time = handle.split() #creating new list time2 = time[5] #print(time2) time3 = time2.split(':') #print(time3) time4 = time3[0] #print(time4) count[time4] = count.get(time4,0) + 1 #print(time4,count[time4]) timelst = list() for timekey,valuekey in list(count.items()): timelst.append((valuekey,timekey)) timelst.sort(reverse=True) for valuekey,timekey in timelst: print(timekey,valuekey)

8th Nov 2017, 12:56 AM
Aric Dunn
Aric Dunn - avatar
4 odpowiedzi
0
dicts are unordered collections.
8th Nov 2017, 1:10 AM
Dark0d3
Dark0d3 - avatar
0
yes. I broke the dict into a list/tuple been trying to sort that correctly and I cant figure it out...
8th Nov 2017, 1:12 AM
Aric Dunn
Aric Dunn - avatar
0
I know.. I dont see the problem.... I have it split to a list.....
8th Nov 2017, 1:18 AM
Aric Dunn
Aric Dunn - avatar