last day (15 days later) » 

10:11 PM
1
A: Python loop through list and return "out of sequence" values

arekolekShort answer, general solution Using my answer to the "Longest increasing subsequence" question, this could be implemented simply as: def out_of_sequence(seq): indices = set(longest_subsequence(seq, 'weak', key=lambda x: x[0], index=True)) return [e for i, e in enumerate(seq) if i not in in...

 
initial testing looking good! What was that edit just now?
 
@Trees4theForest you can see all edits if you click the "edited X time ago" link. But in this case, I changed only some comments and variable names, nothing of real significance.
 
been testing regularly, and it works -- awesome! For my understanding, what is the key=None arg (and subsequent lambda x: x) doing through this
 
I've added an explanation to my answer.
 
Hi @arekolek - I can't thank you enough for the work, and the explanation. However, I did just find one limitation: If the first run of out-of-sequence items is longer than the first run of in-sequence items, then regardless of how many in-sequence items follow, the function returns that initial run of in-sequence items. IE 1,2,3,991,992,993,994,5,6,7,8,9,10,11... returns: 1,2,3
 
10:11 PM
That's interesting, but also weird because it returns 991,992,993,994 for me. But if you are sure there's a problem, I think it's best to post a new question.
 
Try the reverse: 991, 992, 993, 1, 2, 3, 4, 5, 994, 995, 996, 997, 998, 999
 
Therefore when you say "out of sequence", the word sequence does not refer to the longest nondecreasing subsequence, since 1 2 3 4 5 994 995 996 997 998 999 is longer than 991 992 993 994 995 996 997 998 999, so the answer 991 992 993 would satisfy you if that was the case. You need to update your question (or post a new one) and include a better definition of the sequence to which the elements shall not belong. I found two problems related to LIS, one is Range-Constrained LIS, and the other is Slope-Constrained LIS. See if the formulation of any of them meets your criteria.
If you can't figure out a formal definition for the sequence you're after, showing more simple examples (like the one in your last comment), along with expected result and explanation for why you expect it, could possibly be enough for others to come up with a problem statement that works for you. For example in the sequence 991 1 2 3 4 5 6 7 8 9 992 993 994 995 996 997 998 999 1000 would you say that 991 or 1 2 3 4 5 6 7 8 9 are out of sequence and why?
 
Thanks - ultimately the "sequence" is determined by the entire list: the longest non-decreasing run of all items considered "en masse" EG for 1, 991, 992, 2, 993, 3 it's impossible to know... For 1, 991, 992, 2, 993, 3, 4 it's 1,2,3,4.
 
Actually, for 1, 991, 992, 2, 993, 3 isn't 1, 991, 992, 993 the sequence?
 

  last day (15 days later) »