MathGroup Archive 2011

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

Search the Archive

Re: Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121088] Re: Replace
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 26 Aug 2011 05:26:26 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j35am1$og8$1@smc.vnet.net>

Am 25.08.2011 13:12, schrieb Sam Korn:
> 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

Hi Sam,

  apply the function {Alternatives[##]}&

In[1]:= lst = RandomInteger[9, {5, 2}]
Out[1]= {{0, 5}, {5, 6}, {7, 9}, {8, 8}, {9, 8}}

In[2]:= Apply[{Alternatives[##1]} & , lst, {1}]
Out[2]= {{0 | 5}, {5 | 6}, {7 | 9}, {8 | 8}, {9 | 8}}


Peter




  • Prev by Date: Re: Incompletely simplified Square root.
  • Next by Date: Re: discrete Fourier transform
  • Previous by thread: Re: Replace
  • Next by thread: Re: Replace