0

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

Jett
  • 2,421
  • 5
  • 16
  • 14
  • 1
    Use the input like an array and see related question http://stackoverflow.com/questions/991350/counting-repeated-characters-in-a-string-in-python – Mihai8 Mar 13 '13 at 23:41
  • 2
    The term for this is (a non-graphical) [histogram](http://en.wikipedia.org/wiki/Histogram), which should aid in *searches*. –  Mar 13 '13 at 23:43

1 Answers1

6

Why not use Counter:

from collections import Counter
Counter("11234458881")

returns:

Counter({'1': 3, '8': 3, '4': 2, '3': 1, '2': 1, '5': 1})
Jason Sperske
  • 29,816
  • 8
  • 73
  • 124