>>> from collections import Counter
>>> Counter(['apple','cherry','coffee','apple','coffee','coffee'])
Counter({'coffee': 3, 'apple': 2, 'cherry': 1})
>>> for k,v in _.items():
... print k,v
...
cherry 1
coffee 3
apple 2
More Related Contents:
- Removing duplicates in lists
- How to generate all permutations of a list?
- How to split text without spaces into list of words
- Understanding recursion in Python
- Find all combinations of a list of numbers with a given sum
- Why is Bubble Sort implementation looping forever?
- Edit Distance in Python
- Find longest repetitive sequence in a string
- Python string ‘in’ operator implementation algorithm and time complexity
- heapq with custom compare predicate
- Simple Python Challenge: Fastest Bitwise XOR on Data Buffers
- Algorithm to find which number in a list sum up to a certain number
- Checking if all elements in a list are unique
- When splitting an empty string in Python, why does split() return an empty list while split(‘\n’) returns [”]?
- Weighted random sample in python
- General bars and stars
- Python Integer Partitioning with given k partitions
- What is the complexity of the sorted() function?
- What’s the algorithm of ‘set.intersection()’ in python?
- How to incrementally sample without replacement?
- Replace list of list with “condensed” list of list while maintaining order
- Python Weighted Random [duplicate]
- How can I interleave or create unique permutations of two strings (without recursion)
- Python: powerset of a given set with generators [duplicate]
- How can I fit a Bézier curve to a set of data?
- All possible paths from one node to another in a directed tree (igraph)
- fastest method of getting k smallest numbers in unsorted list of size N in python?
- Mergesort with Python
- Find non-common elements in lists
- Algorithm for solving Sudoku