We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Company Logo
You are viewing a single comment's thread. Return to all comments →
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()