MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121071] Re: Replace
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 26 Aug 2011 05:23:21 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108251106.HAA24963@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

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 at 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 at yahoo.com




  • References:
    • Replace
      • From: Sam Korn <sam@kornfamily.com>
  • Prev by Date: Re: Incompletely simplified Square root.
  • Next by Date: undocumented limits on subprocesses?
  • Previous by thread: Replace
  • Next by thread: Re: Replace