I have an array, containing some strings split by a comma. I would like to count the amount of duplicate strings and set the number to a variable with the name of the item that appears the most. An example array is below:
“Postage”, “Registry”, “Registry”, “Registry”, “Registry”, “Search Fees”, “Registry”, etc.
The strings in the array will differ almost every time, as will the amount in the array, so I cannot look for specific words or locations. Does anybody have any suggestions on counting the duplicate strings?
Here’s how I would do it: parse the string and create a dictionary with the words as the keys and the values as init counters. If the new work is in the dictionary, increase the counter of that key. Of not, add the new key with the value 1.