Re: Re: split a list
- To: mathgroup at smc.vnet.net
- Subject: [mg40627] Re: [mg40552] Re: [mg40515] split a list
- From: Dr Bob <majort at cox-internet.com>
- Date: Fri, 11 Apr 2003 02:04:15 -0400 (EDT)
- References: <200304100736.DAA24139@smc.vnet.net>
- Reply-to: majort at cox-internet.com
- Sender: owner-wri-mathgroup at wolfram.com
Complement doesn't work, because it returns a sorted list. Bobby On Thu, 10 Apr 2003 03:36:40 -0400 (EDT), <Gary.Anderson at frb.gov> wrote: > > roberto, > > how about > u=Select[r,#<m&];v=Select[r,#>m&] but what about ==? > alternatively, > v=Complement[r,u=Select[r,#<m&]]; > > > > Roberto > Brambilla To: mathgroup at smc.vnet.net > <rlbrambilla@ cc: > cesi.it> Subject: [mg40627] [mg40552] [mg40515] split a list > > 04/09/03 > 01:30 AM > > > > > > > > Hi, > > I have a list (very long, thousands, and unsorted) of numbers > r={n1,n2...} > and for a given a number m I want to split it in the two sublists > (unsorted, same order) u={elements<m], v={elements>m}. > Now I use this *old-style* method: > > u = v = {}; > For[i = 1, i <= Length[r], i++, > tmp = r[[i]]; > If[tmp > m , AppendTo[u, tmp], AppendTo[v, tmp]]; > ] > > Any suggestion for a more efficient (and elegant) method? > Also oneliners are well accepted. > > Many thanks, Roberto > > Roberto Brambilla > CESI > Via Rubattino 54 > 20134 Milano > tel +39.02.2125.5875 > fax +39.02.2125.5492 > rlbrambilla at cesi.it > > > > > > > > -- majort at cox-internet.com Bobby R. Treat
- References:
- Re: split a list
- From: Gary.Anderson@frb.gov
- Re: split a list