You can iterate through the list with a for loop and keep track of the previous values with a variable. If you find three consecutive values that are the same, you can return True. Otherwise, return False. Here's an example:
main.py256 chars13 lines
This function takes a list as an argument and returns True if there are three consecutive values that are the same, and False otherwise.
You can call this function like this:
main.py150 chars6 lines
Here, the first call to has_three_consecutive
returns True because there are three consecutive values of 2 in the list. The second call returns False because there are no three consecutive values that are the same.
gistlibby LogSnag