I have a function def for Markov chain to create sentences. This is def:

```def createProbabilityHash(words):
numWords = len(words)
wordCount = {}
for word in words:
if wordCount.has_key(word):
wordCount[word] += 1
else:
wordCount[word] = 1```

Now I want a definition to build the same thing in processing. Can someone help me out with it? Thank you!

Aug 2, 2019 313 views

## 1 answer to this question.

Try something like this @Gujjar

```HashMap<String, int> wordCount;

int createProbabilityHash(words):
int numWords = words.size();
wordCount = new HashMap<String, int>();
for (int i = 0;i < numWords; ++i) {
if wordCount.containsKey(words[i]) {
wordCount.put(words[i], wordCount.get(words[i]) + 1);
} else {
wordCount.put(words[i], 1);
}
}```
answered Aug 2, 2019 by Ashish

## Calculate probabilities for Markov Chain - Python

You have to use the tuples from ...READ MORE

## Numpy rounds very small number to zeros - Markov Chain(Python)

Use higher-precision floats, if available on your ...READ MORE

## Example to run KNN algorithm using python

Have a look at this one: from sklearn.datasets ...READ MORE

## How do I convert a pandas dataframe to a numpy array using python?

Try something like this: df.values array([[nan, 0.2, nan], ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

Enumerate() method adds a counter to an ...READ MORE

## Lowercase in Python

You can simply the built-in function in ...READ MORE