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


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

Re: Replace

Started byDrMajorBob <btreat1@austin.rr.com>
First post2011-08-26 09:27 +0000
Last post2011-08-26 09:27 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#4573 — Re: Replace

FromDrMajorBob <btreat1@austin.rr.com>
Date2011-08-26 09:27 +0000
SubjectRe: Replace
Message-ID<j37otm$4ie$1@smc.vnet.net>
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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web