• + 0 comments

    Extra challenge: do not use Counter

        s = list(input())
        
        d = {}
        for v in s:
            if v not in d:
                d[v] = 1
            else: 
                d[v] += 1
        
        # sort by value key first (alphabetical order), a through z 
        d = dict(sorted(d.items(), key= lambda x: x[0]))
        
        # sort dictionary by key (occurrence), largest to smallest
        d = dict(sorted(d.items(), key= lambda x: x[1],  reverse=True))
       
        # get first three outputs of the sorted dictionary
        res = {k: v for i, (k, v) in enumerate(d.items()) if i < 3}  
        
        for key, value in res.items():
            print(key, value)