Cases, Pattern, Condition [duplicate]

I supposed Cases would do the list produced as example

li = RandomSample[Range[100, 999], 30]

{290, 651, 448, 970, 771, 185, 214, 691, 654, 608, 709, 130, 551, 315, 797, 701, 719, 633, 276, 888, 105, 879, 466, 853, 786, 976, 874, 907, 718, 798}


and filtered with

cli = Cases[li, {__, x_, y_, __} /; x < y]


I expected {290, 651, 448, 970, 185, 214, 691, 608, 709,...} but received only

{}


Obviously I did something wrong, but after trying to find something alike or consult help or making small variations to the function, I don't know why.

• You are looking for elements that, among other things, are lists. There are no such elements. Commented Nov 15, 2018 at 20:05
• @DanielLichtblau yes true I pretend only to filter cases where one element is lower than the following one ... how to ask this condition without asking to be lists at the same time ... I take out {} in patern it doesn't work neither Commented Nov 15, 2018 at 20:10
• Both of these come close to what I think you want. Flatten[Cases[Partition[li, 2, 1], {x_, y_} /; x < y]] ReplaceList[li, {___, PatternSequence[x_, y_] /; x < y, ___} :> {x, y}] But there is an issue of repeats, when there is a consecutive triple with its two overlapping pairs satisfying the rule. Commented Nov 15, 2018 at 20:10
• @DanielLichtblau -- You gave me the solution I just take the first part of your expresion and made DeleteDuplicates and the work is done!! dlli = DeleteDuplicates[ Flatten[Cases[Partition[li, 2, 1], {x_, y_} /; x < y]] ] Commented Nov 15, 2018 at 20:26
• @AlexeyPopkov , well not, it's made with the expresion I wrote up, RandomSample[Range[100,999],60] this expresion and others I made to make test for evaluating people they need to explain the rule that produces one list from another list here is this x,y are in son list if x<y other selections are with different filters. thanks for your help Commented Nov 16, 2018 at 17:48

You can use SequenceCases:
SequenceCases[li, {x_, y_} /; x < y :> Sequence[x, y]]