Expand|Select|Wrap|Line Numbers
- import math
- probabilities = {"شور": 0.02, "نمک": 0.05,"زندگی": 0.07, "غذاهای": 0.01, "غذای": 0.05}
- filename = "F.txt"
- for line in open(filename, encoding="utf-8"):
- list_line = line.split("\t")
- words = list_line[0].split()
- for key, value in probabilities.items():
- for word in words:
- if word == key:
- result = sum(math.log(value))
- print(word, result, end=" ")
- print()
If you omit sum from the code and then run it, you can see how the numbers are located.
Hint: I want to sum the words of each line separately.
for example if I have 4 sentences, I should have 4 numbers finally.