I have this code:
palavras = dataClean.split()
count = 1
for palavra, frequencia in palavras:
aleatorio = random.uniform(0.0, 1.0)
if aleatorio < 0.5:
count += 1
contProb[palavra] = count
count = 0
print(contProb)
For example, for this txt:
olá mundo olá mundo adeus
So I wanted it to work like this: no for
must be able to read each letter of the given text and each letter increment according to the result of if
.
Let me give you an example:
The counter always starts with a value of 1 for all letters. We read the word ola
in the variable aleatorio
the random number created is 0.4, that is, it should increment 1 to count
. After that we should read the second word mundo
and if, for example, aleatorio
for 0.3 must increment 1 to count
but the count is already 2, that is, increment will increment 3 and save. And that's not what you should do.
I mean, do I need several counters? How do I do this?