Re: Mapping Functions That Take More Than One Argument
- To: mathgroup at smc.vnet.net
- Subject: [mg69878] Re: Mapping Functions That Take More Than One Argument
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 26 Sep 2006 05:21:22 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <efaclu$1uo$1@smc.vnet.net>
Gregory Lypny wrote: > Hello everyone, > > How can I map a functions onto sub-lists when the function takes more > than one argument. I can't seem to stumble upon the right syntax. > > Here's a list of three sub-lists. > > {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} > > I want to drop the first element of each sub-list, that is, 1 from > the first, 4 from the second, and 7 from the third. > > Drop[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 1] > > gives me > > {{4, 5, 6}, {7, 8, 9}}, > > which is what I expected (I'm learning) but not what I want. So, how > do I apply Drop to each sub-list? > > Regards, > > Gregory > Hi Gregory, Use the Map function to go down one level by default. Some alternatives are also listed. In[1]:= lst = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; In[2]:= (Drop[#1, 1] & ) /@ lst Out[2]= {{2, 3}, {5, 6}, {8, 9}} In[3]:= Rest /@ lst Out[3]= {{2, 3}, {5, 6}, {8, 9}} In[4]:= (Delete[#1, 1] & ) /@ lst Out[4]= {{2, 3}, {5, 6}, {8, 9}} In[5]:= lst /. {(x_)?AtomQ, y__} :> {y} Out[5]= {{2, 3}, {5, 6}, {8, 9}} Cheers, Jean-Marc