Re: Mapping Functions That Take More Than One Argument
- To: mathgroup at smc.vnet.net
- Subject: [mg69890] Re: Mapping Functions That Take More Than One Argument
- From: Peter Pein <petsie at dordos.net>
- Date: Wed, 27 Sep 2006 06:03:40 -0400 (EDT)
- References: <efaclu$1uo$1@smc.vnet.net>
Gregory Lypny schrieb: > 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 > Hello Gregory, at least four ways to do this come to my mind immediately; but I would use only the first one: lst = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Rest /@ lst (*or Map[Rest,lst] *) --> {{2, 3}, {5, 6}, {8, 9}} Drop[list,1] is the same as Rest[list]: (Drop[#1, 1] & ) /@ lst one can use patterns: lst /. {Except[_List], r___} :> {r} or become cumbersomely Transpose[Rest[Transpose[lst]]] Peter