python histogram one-liner
- by mykhal
there are many ways, how to code histogram in Python.
by histogram, i mean function, counting objects in an interable, resulting in the count table (i.e. dict). e.g.:
>>> L = 'abracadabra'
>>> histogram(L)
{'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r': 2}
it can be written like this:
def histogram(L):
d = {}
for x in L:
…