MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: pattern matching all list elements but last

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54557] Re: [mg54539] pattern matching all list elements but last
  • From: "Harvey P. Dale" <hpd1 at nyu.edu>
  • Date: Wed, 23 Feb 2005 03:11:29 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Trevor:


Flatten[Join[{100+Most[#],Last[#]}]]&/@{{1},{2,3},{4,5,6},{7,8,9,10}}

            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

tel: 212-998-6161

fax: 212-995-3149

fax: 914-234-0940



-----Original Message-----
From: Trevor Baca [mailto:trevorbaca at gmail.com]
To: mathgroup at smc.vnet.net
Subject: [mg54557] [mg54539] pattern matching all list elements but last



hi mathgroup folks,



let's say ls looks like this:



  ls = {{1}, {2,3}, {4,5,6}, {7,8,9,10}}



is there an elegant way to match all integers *except the last

(rightmost)* in each list and, say, add 100 to each?



  ls /. <magic replacement rule goes here>



or



  ls //. <magic replacement rule goes here>



to give {{1}, {102,3}, {104,105,6}, {107,108,109,10}}?



this works:



  Release[ ls //. {a___, b_Integer, c___, z_Integer} :> {a, Hold[b +

100], c, z} ]



but is there a more elegant pattern, possibly one that avoids the

Hold-Release trick?





trevor.


  • Prev by Date: Re: Pseudo-Random Numbers??
  • Next by Date: Re: my mathematica no longer renders graphics, even after reinstall
  • Previous by thread: Re: pattern matching all list elements but last
  • Next by thread: Re: pattern matching all list elements but last