how to find 2 similar words in atext python 1

how to find 2 similar words in atext python

words = sentence.split()
counts = {}
for word in words:
    if word not in counts:
        counts[word] = 0
    counts[word] += 1

Here is what the above code is Doing:
1. We create an empty dictionary called counts.
2. We loop through the list of words and check if the word is in the dictionary.
3. If the word is not in the dictionary, we create a new item with the word as the key and the value 0.
4. If the word is in the dictionary, we increment the value of that key by 1.

Similar Posts