I have a list  l = [1,2,2,3,1,1,2,3,4,5,6]
I don't want to use  l.count(element)  method. I don't want to use for loop or iterator.
output like  {1: 3, 2: 3, 3: 2, 4: 1, 5: 1, 6: 1} 
            Asked
            
        
        
            Active
            
        
            Viewed 1,632 times
        
    1
            
            
         
    
    
        Mairaj Khan
        
- 369
- 3
- 13
1 Answers
3
            Use collection's Counter:
>>> from collections import Counter
>>> l = [1,2,2,3,1,1,2,3,4,5,6]
>>> Counter(l)
Counter({1: 3, 2: 3, 3: 2, 4: 1, 5: 1, 6: 1})
 
    
    
        mdml
        
- 22,442
- 8
- 58
- 66