Re: match 1, replace 2
- To: mathgroup at smc.vnet.net
- Subject: [mg56239] Re: [mg56199] match 1, replace 2
- From: "Christoph Lhotka" <lhotka at astro.univie.ac.at>
- Date: Wed, 20 Apr 2005 05:30:15 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi, I do not see what you want to achieve with Sequence[100+n,-1], but the right pattern to do some substitution like yours is: In[..]:= ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}}; In[..]:= ls /. {n___Integer, m_Integer} :> {f[n], m} Out[..]:= {{f[1, 2], 3}, {f[4], 5}, {f[6, 7, 8], 9}} (which means to modifiy all but the last element by some function f...) with kind regards... On Tue, 19 Apr 2005 04:54:55 -0400 (EDT) "Trevor Baca" <trevorbaca at gmail.com> wrote: > hi mathgroup, > > what rule takes > > ls = {{1, 2, 3}, {4, 5}, {6, 7, 8, 9}} > > to > > {{101, -1, 102, -1, 3}, {104, -1, 5}, {106, -1, 107, -1, 108, -1, > 9}} > > ie, matches all integers but the last in each list and then replaces > each matched integer n with the 2-element sequence Sequence[100 + n, > -1]? > > trevor. > -- Christoph Lhotka -- University of Vienna Institute for Astronomy Tuerkenschanzstr. 17 1180 Vienna, Austria fon. +43.1.4277.518.41 mail. lhotka at astro.univie.ac.at