Sha256: 083a18063e0da8000086ebd0acf5894436818924fa3b049a27a502efdca3a62c
Contents?: true
Size: 429 Bytes
Versions: 127
Compression:
Stored size: 429 Bytes
Contents
from collections import Counter # to be backwards compatible with the old Python 2.X def decode_if_needed(string): try: return string.decode('utf-8') except AttributeError: return string def word_count(text): def replace_nonalpha(char): return char.lower() if char.isalnum() else ' ' text = ''.join(replace_nonalpha(c) for c in decode_if_needed(text)) return Counter(text.split())
Version data entries
127 entries across 127 versions & 1 rubygems