Identify if list has consecutive elements that are equal in python

前端 未结 6 1601
情深已故
情深已故 2020-11-28 15:01

I\'m trying to identify if a large given list has consecutive elements that are the same.

So let\'s say

lst = [1, 2, 3, 4, 5, 5, 6]

6条回答
  •  我在风中等你
    2020-11-28 15:23

    My solution for this if you want to find out whether 3 consecutive values are equal to 7. For example, a tuple of intList = (7, 7, 7, 8, 9, 1):

    for i in range(len(intList) - 1):
            if intList[i] == 7 and intList[i + 2] == 7 and intList[i + 1] == 7:
                return True
        return False
    

提交回复
热议问题