How can I get histogram number with pairs by using python code?
Question: I want to take hist no with pairs by using python code like when i put input
11 2 34 21 the output should be like that 11(1) 2(1) 34(1) 21(1)


Answer: First, let's create a list of numbers (I have added some repeats to make it
more interesting):

    
    
    >>> v = ( 11, 2, 34, 21, 2, 2 )
    

Next, let's create a Counter instance:

    
    
    >>> from collections import Counter
    >>> ctr = Counter(v)
    

Now, let's get the counts that you wanted:

    
    
    >>> dict(ctr)
    {2: 3, 11: 1, 34: 1, 21: 1}
    

If you prefer the parenthesized format that you show in the question, then we
need to do some formatting:

    
    
    >>> ' '.join('{}({})'.format(x, ctr[x]) for x in ctr)
    '2(3) 11(1) 34(1) 21(1)'
    

You can read more about the Counter class in the [python
docs](https://docs.python.org/2/library/collections.html#collections.Counter).

