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


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

Re: Replace

From DrMajorBob <btreat1@austin.rr.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace
Date 2011-08-26 09:27 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j37otm$4ie$1@smc.vnet.net> (permalink)
References <201108251106.HAA24963@smc.vnet.net>

Show all headers | 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