-1
這是我的Python腳本:Python的,如果條件繼續解析
mock_data = ((23020, "in0"),
(23000, "in1"),
(23020, "in2"),
(0, "in3"),
(23060, "in4"),
(23080, "in5"),
(23100, "in6"),
(0, "in7"))
mock_len = len(mock_data)
epsilon = 20
max_data = 0
isInInterval = True
for i in range(mock_len - 1):
if isInInterval == True:
if mock_data[i+1][0]-mock_data[i][0] == 20:
max_data = mock_data[i+1][0]
isInInterval = False
print max_data
if max_data != 0 and mock_data[i][0]==0:
isInInterval = True
輸出:
23020
23080
但是,當我的數據更改爲:
mock_data = ((23020, "in0"),
(23000, "in1"),
(23020, "in2"),
(0, "in3"),
(23060, "in4"),
(23080, "in5"),
(23100, "in6"),
(10, "in7"),
(100,"int8"),
(1000,"int9"),
(1020,"int10"),
(300,"int11"))
輸出與我目前的代碼仍然與上面相同,但我也想打印1020:
23020
23080
1020
什麼是我的代碼的最佳變化也包括在目前這種情況下,因爲當我從0
目前還不清楚你試圖實現的是什麼。您是否僅僅試圖在數據中確定新數據集的起始位置,最初您認爲它始終始於零,但現在已經發現新序列的起始位置可能爲0,10,300或其他。如果是這樣,只要新序列的開始總是小於先前的值,那麼可能對'mock_data [i] [0]