Our task is to print the element which occurs 3 consecutive times in a Python list.
Input : [4, 5, 5, 5, 3, 8] Output : 5 Input : [1, 1, 1, 64, 23, 64, 22, 22, 22] Output : 1, 22
- Create a list.
- Create a loop for range size – 2.
- Check if the element is equal to the next element.
- Again check if the next element is equal to the next element.
- If both conditions are satisfied then print the element.
Example 1 : Only one occurrence of a 3 consecutively occurring element.
Example 2 : Multiple occurrences of 3 consecutively occurring elements.
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.
- Python | Check if list contains consecutive numbers
- Python program to find common elements in three lists using sets
- Python | Find common elements in three sorted arrays by dictionary intersection
- Python | Merge List with common elements in a List of Lists
- Python | Check if list contains all unique elements
- Python | Check whether string contains only numbers or not
- Python program to find the frequency of the elements which are common in a list of strings
- Python program to check if a string contains all unique characters
- Python program to verify that a string only contains letters, numbers, underscores and dashes
- Python Program for Common Divisors of Two Numbers
- Program to check if a string contains any special character
- Python program for sum of consecutive numbers with overlapping in lists
- Python List Comprehension | Three way partitioning of an array around a given range
- Python | Three element sum in list
- Python - Test if List contains elements in Range
- Python | Test if string contains element from list
- Python program maximum of three
- Python Program to print all Possible Combinations from the three Digits
- Python | Find most common element in each column in a 2D list
- Python | Find common elements in list of lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.