MathGroup Archive 2011

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

Search the Archive

Re: Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121091] Re: Replace
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 26 Aug 2011 05:26:58 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: hanlonr at cox.net

data = RandomInteger[{0, 10}, {4, 2}]

{{1, 0}, {9, 1}, {3, 3}, {0, 7}}

data /. {a_, b_} -> {Alternatives[a, b]}

{{1 | 0}, {9 | 1}, {3 | 3}, {0 | 7}}

{Alternatives @@ #} & /@ data

{{1 | 0}, {9 | 1}, {3 | 3}, {0 | 7}}

List /@ (Alternatives @@ # & /@ data)

{{1 | 0}, {9 | 1}, {3 | 3}, {0 | 7}}

List /@ Alternatives @@@ data

{{1 | 0}, {9 | 1}, {3 | 3}, {0 | 7}}

% == %% == %%% == %%%%

True

data /. {a_, b_} :> "(" <> ToString[Alternatives[a, b]] <> ")"

{"(1 | 0)", "(9 | 1)", "(3 | 3)", "(0 | 7)"}

"(" <> ToString[Alternatives @@ #] <> ")" & /@ data

{"(1 | 0)", "(9 | 1)", "(3 | 3)", "(0 | 7)"}

"(" <> ToString[#] <> ")" & /@ (Alternatives @@ # & /@ data)

{"(1 | 0)", "(9 | 1)", "(3 | 3)", "(0 | 7)"}

"(" <> ToString[#] <> ")" & /@ Alternatives @@@ data

{"(1 | 0)", "(9 | 1)", "(3 | 3)", "(0 | 7)"}

% == %% == %%% == %%%%

True


Bob Hanlon

---- 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





  • Prev by Date: Re: discrete Fourier transform
  • Next by Date: Re: Replace
  • Previous by thread: Re: Replace
  • Next by thread: Re: Replace