Sort by

recency

|

1249 Discussions

|

  • + 0 comments

    Without modifying the code already given :)

    from collections import Counter
    
    if __name__ == '__main__':
        s = input()
        c = Counter(s)
        [print(letter, rep) for letter, rep in Counter(sorted(c.elements())).most_common(3)]
    
  • + 0 comments
    def my_func(s):
        chars_dict = {}
        str_list = list(s)
        for char in str_list:
            if char in chars_dict:
                chars_dict[char] += 1
            else:
                chars_dict[char] = 1
        return chars_dict
    if __name__ == "__main__":
        s = input()
        norm_list = my_func(s).items()
        srtd_norm_list = sorted(norm_list)
        sorted_data = sorted(srtd_norm_list, key=lambda x: x[1], reverse=True)
        counter = 0
        for i, j in sorted_data:
            print(f"{i} {j}")
            counter += 1
            if counter == 3:
                break
    
  • + 0 comments
    if __name__ == '__main__':
        s = input()
        ch = {}
    
        for i in s:
            ch[i] = ch.get(i, 0) + 1
            
        sorted_by_keys = dict(sorted(ch.items()))
        sorted_by_values = dict(sorted(sorted_by_keys.items(), key=lambda item: item[1], reverse=True)[:3])
    
        for key, value in sorted_by_values.items():
            print(key, value)
    
  • + 0 comments

    from collections import Counter

    if name == 'main': s = sorted(input()) z= Counter(s) z=Counter(s).most_common(3) for x in z: print(*x)

  • + 1 comment
    if __name__ == '__main__':
        s = input()
        d = {}
        l = []
        for c in s:
            d[c] = d.get(c, 0) + 1
        for k, v in d.items():
            l.append((k, v))
        l.sort(key=lambda x: (-x[1], x[0]))
        for i in range(3):
            print(l[i][0], l[i][1], sep=" ")