Question

For example let say

numbers=input("Enter numbers: ")

If someone inputs 11234458881

How can I make the output

1 occurs 3 times

2 occurs 1 time

3 occurs 1 time

4 occurs 2 times

And so on

Was it helpful?

Solution

Why not use Counter:

from collections import Counter
Counter("11234458881")

returns:

Counter({'1': 3, '8': 3, '4': 2, '3': 1, '2': 1, '5': 1})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top