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

Version Path
trackler-2.0.8.27 tracks/python/exercises/word-count/example.py
trackler-2.0.8.26 tracks/python/exercises/word-count/example.py
trackler-2.0.8.24 tracks/python/exercises/word-count/example.py
trackler-2.0.8.23 tracks/python/exercises/word-count/example.py
trackler-2.0.8.22 tracks/python/exercises/word-count/example.py
trackler-2.0.8.21 tracks/python/exercises/word-count/example.py
trackler-2.0.8.20 tracks/python/exercises/word-count/example.py
trackler-2.0.8.19 tracks/python/exercises/word-count/example.py
trackler-2.0.8.18 tracks/python/exercises/word-count/example.py
trackler-2.0.8.17 tracks/python/exercises/word-count/example.py
trackler-2.0.8.16 tracks/python/exercises/word-count/example.py
trackler-2.0.8.15 tracks/python/exercises/word-count/example.py
trackler-2.0.8.14 tracks/python/exercises/word-count/example.py
trackler-2.0.8.13 tracks/python/exercises/word-count/example.py
trackler-2.0.8.12 tracks/python/exercises/word-count/example.py
trackler-2.0.8.11 tracks/python/exercises/word-count/example.py
trackler-2.0.8.10 tracks/python/exercises/word-count/example.py
trackler-2.0.8.9 tracks/python/exercises/word-count/example.py
trackler-2.0.8.8 tracks/python/exercises/word-count/example.py
trackler-2.0.8.7 tracks/python/exercises/word-count/example.py