count frequency

mail@pastecode.io avatar
unknown
plain_text
a year ago
368 B
1
Indexable
Never
def count(text):
    words = text.split()
    word_count = {}
    frequency = []

    for i in words:
        if i not in word_count:
            word_count[i] = 0
            frequency.append(0)
        else:
            word_count[i] += 1
            frequency.append(word_count[i])

    return frequency

print(count('one two one tho three one two'))