3 ms·
Worth noting that Counter itself uses what the article calls get Method, but with a common performance optimization (caching a bound method). def _count_el
by mgraczyk 11y ago
Worth noting that Counter itself uses what the article calls get Method, but with a common performance optimization (caching a bound method).
def _count_elements(mapping, iterable):
mapping_get = mapping.get
for elem in iterable:
mapping[elem] = mapping_get(elem, 0) + 1
- raymondh 11y agoAlso worth noting that those lines are immediately followed by: try: # Load C helper function if available from _collections import _count_elements except ImportError: pass