In Python, how do I create and array from words from multiple lists, with word occurrences : <p>I have a JSON file that has multiple objects with a text field:</p>

<pre><code>{
"messages": 
[
    {"timestamp": "123456789", "timestampIso": "2019-06-26 09:51:00", "agentId": "2001-100001", "skillId": "2001-20000", "agentText": "That customer was great"},
    {"timestamp": "123456789", "timestampIso": "2019-06-26 09:55:00", "agentId": "2001-100001", "skillId": "2001-20001", "agentText": "That customer was stupid\nI hope they don't phone back"},
    {"timestamp": "123456789", "timestampIso": "2019-06-26 09:57:00", "agentId": "2001-100001", "skillId": "2001-20002", "agentText": "Line number 3"},
    {"timestamp": "123456789", "timestampIso": "2019-06-26 09:59:00", "agentId": "2001-100001", "skillId": "2001-20003", "agentText": ""}
]
}
</code></pre>

<p>I'm only interested in the 'agentText' field.</p>

<p>I basically need to strip out every word in the agentText field and do a count of the occurrences of the word.</p>

<p>So my python code:</p>

<pre><code>import json

with open('20190626-101200-text-messages.json') as f:
  data = json.load(f)

for message in data['messages']:
    splittext= message['agentText'].strip().replace('\n',' ').replace('\r',' ')
    if len(splittext)&gt;0:
        splittext2 = splittext.split(' ')
        print(splittext2)
</code></pre>

<p>gives me this:</p>

<pre><code>['That', 'customer', 'was', 'great']
['That', 'customer', 'was', 'stupid', 'I', 'hope', 'they', "don't", 'phone', 'back']
['Line', 'number', '3']
</code></pre>

<p>how can I add each word to an array with counts?
so like;</p>

<pre><code>That 2
customer 2
was 2
great 1
..
</code></pre>

<p>and so on?</p>
