Re: Cases and Nonatomic expression

• To: mathgroup at smc.vnet.net
• Subject: [mg56731] Re: Cases and Nonatomic expression
• From: "Valeri Astanoff" <astanoff at yahoo.fr>
• Date: Thu, 5 May 2005 06:01:14 -0400 (EDT)
• References: <d59lfg\$6i6\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Swati Shah a écrit :
> Hi Everyone
> I have a list
> k = {{1,1,2,2,3}, {1,2,2,2,3}, {2,3,3,3,3}, {5,2,2,2,1}, {6,1,1,1,1},
> {6,1,1,1,1}}
> If the first element of the sublist is 1 I want to append the sublist
to
> g1, if it starts with 2 then append g2 or starts with 6 then append
to g6
[...]

You could do it this way :

In[1]:=
k={{1,1,2,2,3},{1,2,2,2,3},{2,3,3,3,3},{5,2,2,2,1},{6,1,1,1,1},{6,1,1,1,1}};

In[2]:= ClearAll["g*"];
nn = Union[k[[All, 1]]];
Evaluate[Symbol["g" <> ToString[#]]& /@
nn] = (Function[{n}, Select[k, #[[1]] == n&]] /@ nn);

In[5]:= g1

Out[5]= {{1,1,2,2,3},{1,2,2,2,3}}

In[6]:= g2

Out[6]= {{2,3,3,3,3}}

In[7]:= g5

Out[7]= {{5,2,2,2,1}}

In[8]:= g6

Out[8]= {{6,1,1,1,1},{6,1,1,1,1}}

v.a.

```

• Prev by Date: Bug in Integrate in Version 5.1?
• Next by Date: Controlled evaluation of functions
• Previous by thread: Re: Cases and Nonatomic expression
• Next by thread: Re: Cases and Nonatomic expression