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


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

Re: Replace

From Bob Hanlon <hanlonr@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace
Date 2011-08-26 09:37 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j37pgq$4o5$1@smc.vnet.net> (permalink)

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web