Python’s general purpose built-in containers are dict ( E.g. {‘a’:1, ‘b’:2, ‘c’:3} ), list ( E.g. [1,2,3,4] ), set ( E.g. {1,2,3,4 } ), and tuple ( E.g. (1,2,3,4) ). Following are specialised container datatypes providing alternatives. Counter
|
1 2 3 4 5 |
from collections import Counter list1 = ['x','y','z','x','x','x','y', 'z'] print(Counter(list1)) |
Output:…