RE: split a list
- To: mathgroup at smc.vnet.net
- Subject: [mg40572] RE: [mg40515] split a list
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 10 Apr 2003 03:40:39 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Roberto, What about this simple approach: list = Table[Random[Integer, {0, 20}], {20}] {20, 13, 16, 12, 9, 0, 2, 19, 8, 12, 16, 0, 18, 20, 18, 4, 4, 12, 6, 3} lowlist = Select[list, # <= 10 &] highlist = Select[list, # > 10 &] {9, 0, 2, 8, 0, 4, 4, 6, 3} {20, 13, 16, 12, 19, 12, 16, 18, 20, 18, 12} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Roberto Brambilla [mailto:rlbrambilla at cesi.it] To: mathgroup at smc.vnet.net 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