How to use 'python count occurrences of all items in list' in Python

Every line of 'python count occurrences of all items in list' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
27def _count(elem: object, ls, index: int) -> int:
28 if index < len(ls):
29 if ls[index] == elem:
30 return 1 + _count(elem, ls, index + 1)
31 else:
32 return _count(elem, ls, index + 1)
33 return 0
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

29def count_value(lst, key):
30 d = {}
31 for obj in lst:
32 val = obj[key]
33 if val in d:
34 d[val] = d[val] + 1
35 else:
36 d[val] = 1
37 return d.iteritems()

Related snippets