JSFiddle - React, Tailwind, and code Playground

by Gonzalo

JavaScript

name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
counts = dict()
for line in handle:
    if line.startswith("From "):
        line = line.rstrip()
        line = line.split()
        time = line[5].split(":")
        hour = time[0]

        counts[hour] = counts.get(hour, 0) + 1
      
lst1 = list()
for key,val in counts.items():
    lst1.append((key,val))
     
 # you don't want to sort for every item it must be at the end of the for loop
#make new loop    
    
    #print key,val
lst1.sort()
for key,val in lst1:
    print key,val