RE: split a list
- To: mathgroup at smc.vnet.net
- Subject: [mg40571] RE: [mg40515] split a list
- From: "Harvey P. Dale" <hpd1 at nyu.edu>
- Date: Thu, 10 Apr 2003 03:40:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Roberto: Use Select. From the original list (r) for example: list1=Select[r,#<m&] list2=Select[r,#>m&] Of course, neither list1 nor list2 will contain any elements of r that exactly equal m, unless you change one of conditions to select any such. Best, Harvey Harvey P. Dale University Professor of Philanthropy and the Law Director, National Center on Philanthropy and the Law New York University School of Law Room 206A 110 West 3rd Street New York, N.Y. 10012-1074 -----Original Message----- From: Roberto Brambilla [mailto:rlbrambilla at cesi.it] To: mathgroup at smc.vnet.net Subject: [mg40571] [mg40515] split a list 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