Powershell to find duplicates in an Array just like Python's cool Counter class.
As we know Python comes with a lot of cool utility modules that helps devs to achieve more in less time one such thing is Counter class that would convert a list of duplicate elements into a dictionary with the count of how many times that element appeared in the list.
As we can see in just one line of code we have found duplicates with the count of their occurrences in the list.
So, how to achieve the same in powershell. Simple! convert the list to a hashtable [FYI , optimization is not the goal here.].
We are iterating over the given array and during the iteration check if the current item is already a key in the hashtable, if not then add to hashtable and assign a value of 1 and if it is already there then simply increment the value by 1.
Delivery Leader at Kyndryl
3moI knew that it would not stop you from exploring 🤣
Delivery Leader at Kyndryl
3moI know on why got to work on this. 🤣