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: [mg54631] Re: pattern matching all list elements but last
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Thu, 24 Feb 2005 03:21:36 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 2/23/05 at 3:11 AM, hanlonr at cox.net (Bob Hanlon) wrote:

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

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

>{{1},{102,3},{104,105,6},{107,108,109,10}}

Hmm... Although I consider myself reasonably proficient with Mathematica, it would not have occurred to me to use pattern matching for this problem. Instead, I would have done

{Sequence@@(Most@#+100),Last@#}&/@ls

which results in the same output.

This raises an interesting question. In general, which approach to a problem gives better performance? Pattern matching or the more functional approach?
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: problems plotting a derivative
  • Next by Date: Re: Labels on graphs
  • Previous by thread: Re: pattern matching all list elements but last
  • Next by thread: Re: pattern matching all list elements but last