MathGroup Archive 2011

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

Search the Archive

Re: Delete elements from list..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116653] Re: Delete elements from list..
  • From: Achilleas Lazarides <achilleas.lazarides at gmx.com>
  • Date: Wed, 23 Feb 2011 05:22:19 -0500 (EST)

Do you really want the resulting list to only have increasing elements? then something like

Module[{tmpl = mylist[[1]]},
 	Scan[(If[# > tmpl, Sow[#]; tmpl = #]) &,
    		mylist]; // Reap]

should work (except that it eats the first element).

If you actually meant that you want to delete any element that is not strictly larger than the previous, then

Module[{tmpl = mylist[[1]]},
 	Scan[(If[# > tmpl, Sow[#]]; tmpl = #) &,
    		mylist]; // Reap]

(which again eats the first element).

On Feb22, 2011, at 1:30 AM, Maarten van der Burgt 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: weibull plot on weibull scaled paper
  • Next by Date: how packages work
  • Previous by thread: Re: Delete elements from list..
  • Next by thread: Re: Delete elements from list..