我想知道如何查找列表中的一行中是否存在一定数量的连续数字,例如
例如,如果我正在寻找两个 1,那么:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", 1, 4, 6] #after my function has been through the list.
如果我正在寻找三个 1 那么:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", "true", 4, 6] #after my function has been through the list.
我努力了:
list = [1, 1, 2, 1]
1,1,1 in list #typed into shell, returns "(1, 1, True)"
任何帮助将不胜感激,我主要想了解发生了什么,以及如何检查列表中的下一个元素是否与第一个 x 数量相同。