I am not sure if this question has been asked before but I couldn't find anything similar from the question list. I would like to check if a list has a set of three values in a certain order. For example, I would like to check if an int list has a set of values 1, 2, 3 anywhere within that list. The length of the list is unknown and the list cannot be sorted.
Example:
Values to check: 1, 2, 3 (in this order)
Example of a list = [1, 1, 2, 3, 1]
This is what I have tried so far.
list1 = [1, 1, 2, 3, 1]
list2 = [1, 1, 4, 3, 1, 2, 1]
def checkValue:
for i in range (0, len(nums)):
if (nums[i+2] - nums[i+1] == nums[i+1] - nums[i]) == 1:
return True
return False
list1 --> return True list2 ---> IndexError: list index out of range
EDIT: Thanks to those who answered and thank you for the list to the sublist question. I never thought that the set of integers can be considered as a sublist and use it to compare to a larger list.