Write a Python program to check if the list contains three consecutive common numbers in Python


The program is checking for a sequence of three consecutive elements that are the same in a list called "a". It starts by defining a variable "l" which is the length of the list "a". Then, it uses a for loop to iterate through the elements in the list. For each iteration, it checks if the current element, the element immediately following it, and the element two spaces after it are all the same. If they are, it prints that element. This checks for any sequence of three consecutive elements in the list that are the same and prints them if they are found.

Source Code

# creating the aay
a = [18, 18, 18, 6, 3, 4, 9, 9, 9]
l = len(a)
for i in range(l - 2):
	if a[i] == a[i + 1] and a[i + 1] == a[i + 2]:
		print(a[i])

Output

18
9



Example Programs