• + 1 comment

    Does anyone know why i keep getting this wrong:

    import math import os import random import re import sys

    words = {}

    if name == 'main': s = input()

    for x in range(len(s) - 1, -1, -1):
        if s[x] not in words:
            words[s[x]] = 1
        else:
            words[s[x]] += 1
    
    # Sort the dictionary by frequency (ascending)
    fixed = sorted(words.items(), key=lambda item: item[1])
    
    # Display the sorted results
    for char, freq in fixed:
        print(f"{char} {freq}")