Python finding n consecutive numbers in a list
- by lost_in_code
I want to know how to find if there is a certain amount of consecutive numbers in a row in my list e.g.
For example if I am looking for two 1's then:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", 1, 4, 6] #after my function has been through the list.
If I am looking for three 1's then:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", "true", 4, 6] #after my function has been through the list.
I have tried:
list = [1, 1, 2, 1]
1,1,1 in list #typed into shell, returns "(1, 1, True)"
Any help would be greatly appreciated, I mainly would like to understand whats going on, and how to check if the next element in the list is the same as the first x amount.