Problem
tl; dr - the code below shows an algorithm that I want to improve by trying some other approach.
Now a long explanation.
Given a list of integers, I would like to find every sequence of consecutive integers that either coincide with the starting point of the sequence, or higher. The sequence should also be longer than the sequential sequence with a higher rank.
You are probably quite confused. Let me just illustrate what I mean.
When I have a list of integers, I can expand it to represent its ranges. Example:
2,1,1,3,3,1
becomes
-,-,-,3,3,-
2,-,-,2,2,-
1,1,1,1,1,1
, , . , .
/, .
, 0 , , . [1, 6, 5]: 1 , , 6 , 5 .
. . . [2,1,0]. , 2 . ! ! . , .
: [3,2,4]
[[1,6,5],[2,1,0],[3,2,4]]
, . 100% , .
[3,3,3,2,1] -> [[1,5,4],[2,4,3],[3,3,2]]
[7,7,3,0,1,2,3] -> [[1,3,6],[2,2,6],[3,3,2],[3,1,6],[7,2,1]]
[0,0,0] -> []
[0,1,0,4,0,1,0] -> [[1,1,1],[4,1,3],[1,1,5]]
, 1. , , . , , , . , :
[2,4,4,4,1], looking at 3*4
[1,8,8], looking at 2*8
[9,9,9,8], looking at 3*9
[9,7,4], looking at 2*7 (sequence doesn't formally exist as [7,7],
but would be in the results, as described above)
, , .
:
[4,4,2,1,1,3]
. , ! , , - 2... 2 . ... . ([4,2,1]) . , :
[2,2,2,1,1,3]
! 2 . , , , 3. , huzzah, , . , ([3,1,5]) , 1:
[2,2,2,1,1,1]
. [2,3,2].
[1,1,1,1,1,1]
, , . , , [1,6,5], .
[[4,2,1], [3,1,5], [2,3,2], [1,6,5]].
, ... .
, . :
def ListProcessing(listL, length, freq):
listL.extend([0])
for checkNum in reversed(list(set(sorted(listL))-set(range(length)))):
seqLen = 0
for index, val in enumerate(listL):
if val >= checkNum:
seqLen += 1
else:
if seqLen > freq-1:
newVal = max(val, listL[index-seqLen-1])
listL[index-seqLen:index] = [newVal] * seqLen
yield(checkNum, seqLen, index-1)
seqLen = 0
AFAIK , , .
- ?
, . , , . .
array.array, . - , .
/ !