Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg54648] Re: pattern matching all list elements but last
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 25 Feb 2005 01:18:47 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <cvhgo5$r1p$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

ls /. {a___, b_Integer} :> {Sequence @@ (100*{a}), b}

??

Regards

  Jens

"Trevor Baca" <trevorbaca at gmail.com> schrieb im Newsbeitrag 
news:cvhgo5$r1p$1 at smc.vnet.net...
> 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: Simplify and Abs
  • Next by Date: Re: Simplify and Abs
  • Previous by thread: Re: pattern matching all list elements but last
  • Next by thread: Re: problems plotting a derivative-- got the solution