3 examples of 'python count frequency in list' in Python

Every line of 'python count frequency 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
19def freq_counter(lst):
20 c = Counter()
21
22 for i in lst:
23 c[i] += 1
24
25 return c
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

34def _count(lst):
35 out = {}
36 for l in lst:
37 out[l] = out.setdefault(l, 0) + 1
38
39 return out
231def items_by_frequency(freqdist):
232 """Sort a dictionary by frequency. Return as a list of pairs.
233 """
234 frequency = lambda x: x[1]
235 return sorted(iter(list(freqdist.items())), key=frequency, reverse=True)

Related snippets