Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4573

Re: Replace

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!newspump.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail
From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace
Date Fri, 26 Aug 2011 09:27:18 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <j37otm$4ie$1@smc.vnet.net> (permalink)
References <201108251106.HAA24963@smc.vnet.net>
Reply-To drmajorbob@yahoo.com
Lines 41
NNTP-Posting-Date 26 Aug 2011 08:29:52 GMT
NNTP-Posting-Host 6553c265.news.twtelecom.net
X-Trace DXC=Znd^c^K9540BdhbaOf?SM9C_A=>8kQj6=m^eQlV`f187:Xj>;_IblD0EFiONJ7[Go6U^FRDkJSJC5
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:4573

Show key headers only | View raw


list = RandomInteger[10, {10, 2}]

{{2, 3}, {8, 5}, {8, 0}, {7, 4}, {8, 8}, {1, 0}, {10, 4}, {8, 3}, {5,
   10}, {3, 9}}

list /. {x_, y_} :> x | y

{2 | 3, 8 | 5, 8 | 0, 7 | 4, 8 | 8, 1 | 0, 10 | 4, 8 | 3, 5 | 10,
  3 | 9}

or

Replace[list, {x_, y_} :> x | y, {1}]

{2 | 3, 8 | 5, 8 | 0, 7 | 4, 8 | 8, 1 | 0, 10 | 4, 8 | 3, 5 | 10,
  3 | 9}

The first version (but not the second) will fail if you have only two  
pairs.

Bobby

On Thu, 25 Aug 2011 06:06:37 -0500, Sam Korn <sam@kornfamily.com> wrote:

> Hi, another stupid question. I have a list, and each element in the list  
> is
> a sublist with a pair of integers. How do I replace each element along  
> the
> lines of "{5,6}" with "(5|6)"?
>
> I know it's a stupid question, and there's probably something really  
> obvious
> I'm missing, but I'm really new to Mathematica.
>
> Thanks!
> -Sam


-- 
DrMajorBob@yahoo.com

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Replace DrMajorBob <btreat1@austin.rr.com> - 2011-08-26 09:27 +0000

csiph-web