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


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

Re: Replace

Started byBob Hanlon <hanlonr@cox.net>
First post2011-08-26 09:37 +0000
Last post2011-08-26 09:37 +0000
Articles 1 — 1 participant

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


Contents

  Re: Replace Bob Hanlon <hanlonr@cox.net> - 2011-08-26 09:37 +0000

#4599 — Re: Replace

FromBob Hanlon <hanlonr@cox.net>
Date2011-08-26 09:37 +0000
SubjectRe: Replace
Message-ID<j37pgq$4o5$1@smc.vnet.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@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

[toc] | [standalone]


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


csiph-web