Hello! I need help with building some code to solve the following problem using python 2.7 without importing anything:
From a number imputed form the user i need to print the frequency of each number in descending order:
Example: for an imputed number of 252452321 the code should print "2-4, 5-2, 4-1, 3-1, 2-1 , 1-1". This means is should print that number 2 is found four times, number 5 is found two times, etc.
So far i have used:
x = raw_input('Insert your number here: ') a = list(x) a0 = a.count('0') a1 = a.count('1') a2 = a.count('2') # and so on until a9 = a.count('9') b = [a0, a1, a2, """etc"""] b.sort() print b
And i can continue a bit from here to obtain the result i need (more or less). But i've been told i should not write it like that, i should use loops.. and i'm stuck on writing one that works. Please, can you help me? Thanks in advance.