Sort by

recency

|

1284 Discussions

|

  • + 0 comments
    from collections import Counter
    
    
    if __name__ == '__main__':
      s = input()
      count = Counter(s)
      sort = sorted(count.items(), key = lambda x: (-x[1], x[0]))
      
      for a,b in sort[:3]:
        print(a,b)
    
  • + 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)
    
  • + 0 comments

    if name == 'main': s = input() s_counter = Counter(sorted(s)) top3 = s_counter.most_common(3) for i, (item, value) in enumerate(top3): print(item, value)

  • + 0 comments

    It's such a smart way to tie the logo directly to the identity of the company. Finding the top three most common characters in the company name sounds like a fun mix of design and data—simple, but super effective! Mahadevbook777

  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    from collections import Counter
    
    
    if __name__ == '__main__':
        s = Counter(sorted(input())).most_common(3)
        for i in s:
            print(*i)