0
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’d like it to work this way: no for
shall be able to read each letter of the given text and to increase each letter according to the result of if
.
Let me give you an example:
The counter always starts with the value 1 for all letters. We read the word ola
in the variable aleatorio
the created Random number is 0.4, that is, you must increment 1 to count
. After that we should read the second word mundo
and if, for example, aleatorio
is 0.3 shall increment 1 to count
but Count is already 2, that is, incrementing will increase 3 and save. And that is not what you should do.
I mean, do I need multiple counters? How do I do this
Friend, please, edit your question and add an example how the result would look for this txt you passed
olá mundo olá mundo adeus
; What do you want to end up with? Something like{'olá': 3, 'mundo': 2, 'adeus': 1}
?– nosklo