I have an array with identical values inside it. I want to create an array inside the array containing the name as well as the number of times it had occur in the array. Here's an example of the input and output:
Input:
['apple', 'apple', 'apple', 'pear', 'pear', 'orange', 'apple', 'orange']
will output:
[{'name': 'apple', 'number': 4}, {'name': 'orange', 'number': 2}, {'name': 'pear', 'number': 2}]