I am wondering how efficiently to calculate the distribution of words on array based on the words from another array.
We are given the array of words test the task is to aggregate the occurrences of words from test in new array s
for word in test:
if word not in s:
mydict[s.count(word)] = 0
else:
mydict[s.count(word)] += 1
This code is very slow, partially due to the lack of performance improvements and due to very slow Python's nature in itetations.
What is the best way to improve the above code?