I'm trying to build a simple program that counts how many entries are in a file for a specific hour. I'm targeting the hour-part of the timestamp in the txt-file and counting each one. That all works well but when I print the result I want it to order the hours from 00, 01 and so on up to 22, 23.
This is my code:
hour = []
for x in hour:
hour.append(x[10:12]) #To get just the hour-part of the timestamp.
hour_sorted = (sorted(hour)) #Now the hours are sorted from 00 to 23, all good so far.
counts = Counter(hour_sorted)
for number in counts:
if number in counts:
print(number + ' ' + str(counts[number]))
The problem is that now prints all the hours out of order.
Output example:
10 3
00 2
12 2
21 3
and so on. I want it like this:
00 2
10 3
12 2
21 3
Any ideas what I'm doing wrong?