Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Delete elements from list..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116643] Re: Delete elements from list..
  • From: James Stein <mathgroup at stein.org>
  • Date: Tue, 22 Feb 2011 04:45:25 -0500 (EST)

This would be fast enough for me:

Clear[makeMonotone];
makeMonotone[ inL_List ] :=
   Module[{i = 1, len, outL, x},
   If[(len = inL // Length) == 0,
    Return[ {} ],
    outL = {inL[[1]]}];
   While[++i <= len,
    If[(x = inL[[i]]) > outL[[1]],
     outL = {x, outL}
     ]];
   Reverse[Flatten[outL]]
   ];
mylist = {1, 2, 3, 4, 5, 6, 4, 5, 7, 8, 9};
makeMonotone[mylist]
makeMonotone[{}]
makeMonotone[{1}]
makeMonotone[{2, 2, 2, 2, 2}]
makeMonotone[{1, 2, 1, 2, 1, 2, 3}]


On Mon, Feb 21, 2011 at 4:30 PM, Maarten van der Burgt <
Maarten.VanDerBurgt at kla-tencor.com> wrote:

> Hallo,
>
> I have a list like:
>
> mylist = {1, 2, 3, 4, 5, 6, 4, 5, 7, 8, 9}
>
> I want to delete any element which is not strictly larger than the
> previous element, until my new list has only increasing values.
>
> This means in mylist above I want to delete the 4 and the 5 at position
> 7 and 8.
>
> Any elegant and fast way for doing this?
>
> In practice I want to do this for a large amount (1000) of very large
> lists (1000). So speed is important.
>
> Thanks for your help.
>
> Maarten
>


  • Prev by Date: Re: Rational[a,b] vs Rational[1,2]
  • Next by Date: Re: How to deal with big matrix?
  • Previous by thread: Re: Delete elements from list..
  • Next by thread: Re: Delete elements from list..