Sort by

recency

|

1266 Discussions

|

  • + 0 comments
    from collections import Counter
    
    your_string = input()
    # your_string = "qwertyuiopasdfghjklzxcvbnm"
    char_counts = Counter(sorted(your_string))
    # print(char_counts)  # Output: Counter
    
    _keys = char_counts.most_common(3)
    first_char = _keys[0]
    second_char = _keys[1]
    third_char = _keys[2]
    print(first_char[0] + " " + str(first_char[1]))
    print(second_char[0] + " " + str(second_char[1]))
    print(third_char[0] + " " + str(third_char[1]))
    
  • + 0 comments
    def find_count(inp_str):
        str_len = len(inp_str)
        d = {}
        for s in inp_str:
            s_count = 0
            if s not in d:
                d.update({s: 1})
            else:
                d[s] = d[s] + 1
                
        d = dict(sorted(d.items(), key=lambda item: item[1], reverse=True))
        l1 = []
        for x in d:
            temp_lst = []
            temp_lst.append(x)
            temp_lst.append(d[x])
            l1.append(temp_lst)
        
        d1 = OrderedDict()
        for x in range(len(l1)-1):
            j = x + 1
            while (j < len(l1)):
                if l1[x][1] == l1[j][1] and l1[x][0] > l1[j][0]:
                    temp = l1[j]
                    l1[j] = l1[x]
                    l1[x] = temp
                    j = j + 1
                elif l1[x][1] == l1[j][1] and l1[x][0] < l1[j][0]:
                    j = j + 1
                else:
                    break
        for i in l1:
            d1.update({i[0]: i[1]})
        return d1
    
  • + 0 comments
    char_count= {}
    
    for char in s:
        if char in char_count:
            char_count[char] += 1
        else:
            char_count[char] = 1
    
    char_count = sorted(char_count.items(), key=lambda item: item[0])
    char_count = sorted(char_count, key=lambda item: item[1], reverse=True)
            
    for char in char_count[0:3]:
        print(char[0], char[1])
    
  • + 0 comments
    1. from collections import Counter
    2. if name == 'main':
    3. s = input()
    4. s = list(s)
    5. store = []
    6. counter = Counter(s)
    7. sorted_counter = dict(sorted(counter.items()))
    8. for i in range(3):
    9. max_key = max(sorted_counter,key=sorted_counter.get)
    10. store.append([max_key,str(sorted_counter[max_key])])
    11. sorted_counter.pop(max_key)
    12. [print(" ".join(i)) for i in store]
  • + 0 comments
    c = Counter(sorted(input()))
    for char,freq in c.most_common()[:3]:
      print(char,freq)