当列表中有两个连续的相似数字时,如何打破循环?

How do I break a loop when there are two consecutive similar numbers in a list?

我想将 break 与 for 循环一起使用, 在列表中的任何时候,都可能有与上一个相似的数字。

例如:

x1 = [2,12,43,56,65,34,76,6,77,77,77,77,77,5,6,4,31]
x2 = [2,12,43,56,65,34,76,6,88,88,88,88,88,5,6,4,31]
x3 = [2,12,43,56,65,34,76,6,5,5,5,5,5,5,6,4,31]

如何使用break当i ==77 in x1,i == 88 in x2 and i ==5,这意味着当连续两个值相同时,中断。

注意:我数据比较多,就不打开了。所以,我不知道传感器重复了多少。

我想对值使用索引但失败了。

请帮忙或有什么建议?

存储您处理的最后一个值,如果您再次看到它,您可以从循环中跳出

x1 = [2,12,43,56,65,34,76,6,77,77,77,77,77,5,6,4,31]
x2 = [2,12,43,56,65,34,76,6,88,88,88,88,88,5,6,4,31]
x3 = [2,12,43,56,65,34,76,6,5,5,5,5,5,5,6,4,31]

last_seen = -1

for x in [x1, x2, x3]:
  for current_number in x:
    if current_number == last_seen:
      last_seen = -1
      break

    print current_number.
    last_seen = current_number
  print

回复:https://repl.it/repls/MisguidedReliableNotification