Sometimes, while working with Python lists or in competitive programming setup, we can come across a subproblem in which we need to get an element that has the minimum consecutive occurrence. The knowledge of solution to it can be of great help and can be employed whenever required. Let’s discuss a certain way in which this task can be performed.
groupby() + min() + lambda
This task can be solved using a combination of above functions. In this, we group each occurrence of numbers using groupby() and get the min of it using min(). The lambda function provide utility logic to perform this task.
The original list is : [1, 1, 1, 2, 2, 5, 5, 5, 5] Minimum Consecutive identical Occurring number is : 2
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course