6
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by Mr.Wizard list-manipulation Nov 16 '18 at 11:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ You are looking for elements that, among other things, are lists. There are no such elements. $\endgroup$ – Daniel Lichtblau Nov 15 '18 at 20:05
  • $\begingroup$ @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 $\endgroup$ – Anxon Pués Nov 15 '18 at 20:10
  • 4
    $\begingroup$ 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. $\endgroup$ – Daniel Lichtblau Nov 15 '18 at 20:10
  • 1
    $\begingroup$ @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]] ] $\endgroup$ – Anxon Pués Nov 15 '18 at 20:26
  • 1
    $\begingroup$ @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 $\endgroup$ – Anxon Pués Nov 16 '18 at 17:48
9
$\begingroup$

You can use SequenceCases:

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

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

$\endgroup$
  • $\begingroup$ This is straight I appreciate your teach. Yesterday make small portions of Danie’s expresión and learn how to use partition and then cases... l and today with yours. You help me really, $\endgroup$ – Anxon Pués Nov 16 '18 at 16:06
  • $\begingroup$ @Mr.Wizard Sorry I have not enough capacity to understaand abstraction as you have, I learn as I can. Daniel Lichblau help me, In one comment of you in this place you refered as solution, now I repeatedly read until found one important sentence "... Cases looks elements not sublists ... " or this is my interpretation, Daniel cleverly broke list in a diferent list of pairs with Partition and than HELP me, Also I read several times other options like ReplaceRepeatedly ... SequenceCases ... finally SORRY ... I learnt every time I meet a stone in middle way at darkness $\endgroup$ – Anxon Pués Nov 18 '18 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.