from collections import Counter
      
      result = Counter(original_list)
      

      Python language logoGet occurrences count in list

      Python public recipes

      Get the occurrences of all elements in a list

      >>> from collections import Counter
      >>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
      >>> Counter(z)
      Counter({'blue': 3, 'red': 2, 'yellow': 1})
      

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.