[Date Index]
[Thread Index]
[Author Index]
Re: second simple problem
*To*: mathgroup at smc.vnet.net
*Subject*: [mg99680] Re: [mg99667] second simple problem
*From*: DrMajorBob <btreat1 at austin.rr.com>
*Date*: Mon, 11 May 2009 06:23:05 -0400 (EDT)
*References*: <200905100919.FAA10179@smc.vnet.net>
*Reply-to*: drmajorbob at bigfoot.com
Clear[f, one, two]
f[x_List, rL_List] := Module[{y = x, p = Flatten@Position[x, "M"]},
y[[p]] = PadRight[rL, Length@p, rL];y
]
f[{1, 5, 7, 4, "M", 6, 7, 8, 9, 1, "M", 3, "M", "M"}, {one, two,
three}]
{1, 5, 7, 4, one, 6, 7, 8, 9, 1, two, 3, three, one}
f[{1, 5, 7, 4, "M", 6, 7, 8, 9, 1, "M", 3}, {one, two, three}]
{1, 5, 7, 4, one, 6, 7, 8, 9, 1, two, 3}
or
Clear[g, one, two]
g[x_List, rL_List] := Module[{p = Flatten@Position[x, "M"]},
ReplacePart[x, Thread[p -> PadRight[rL, Length@p, rL]]]]
g[{1, 5, 7, 4, "M", 6, 7, 8, 9, 1, "M", 3, "M", "M"}, {one, two,
three}]
{1, 5, 7, 4, one, 6, 7, 8, 9, 1, two, 3, three, one}
g[{1, 5, 7, 4, "M", 6, 7, 8, 9, 1, "M", 3}, {one, two, three}]
{1, 5, 7, 4, one, 6, 7, 8, 9, 1, two, 3}
Bobby
On Sun, 10 May 2009 04:19:36 -0500, Francisco Gutierrez
<fgutiers2002 at yahoo.com> wrote:
> Dear sirs:
> I have the following list:
> ex={1,5,7,4,"M",6,7,8,9,1,"M",3}
> I want to replace the M's in the following way: the first M by 5, and
> the second by2.
> Thus I have a replacement list
> rL={5,2}
> The problem is to get ={1,5,7,4,5,6,7,8,9,1,2,3}
> How can I do this in the most general form (for any length of ex and any
> number of values of "M")?
> Thanks
> Francisco
>
--
DrMajorBob at bigfoot.com
Prev by Date:
** Re: simple question**
Next by Date:
**Re: TraditionForm Appears to be Inconsistent**
Previous by thread:
**Re: second simple problem**
Next by thread:
**Re: second simple problem**
| |