Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Combining elements of a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108876] Re: Combining elements of a list
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Mon, 5 Apr 2010 08:01:42 -0400 (EDT)

Riffle: that's a function new in Mathematica 6 that I missed completely. 
  Neat!

On 4/4/2010 7:43 AM, Albert Retey wrote:
> Hi,
>
>> How could I go from:
>> {h,e,l,l,o}
>> to
>> {hello}?
>>
>> That is the first step of what I am really looking to do. Which is
>> to go from:
>> {{t,h,i,s},{i,s},{a},{t,e,s,t},{m,e,s,s,a,g,e}}
>> to
>> "this is a test message"
>>
> If you want to join strings, use StringJoin :-)
>
> this works if the entries are symbols:
>
> letters={{t, h, i, s}, {i, s}, {a}, {t, e, s, t}, {m, e, s, s, a,
> g, e}}
>
> StringJoin[Riffle[Map[ToString,letters,{2}], " "]]
>
> if the entries are strings already, this would be enough:
>
> letters = {{"t", "h", "i", "s"}, {"i", "s"}, {"a"}, {"t", "e", "s",
>     "t"}, {"m", "e", "s", "s", "a", "g", "e"}}
>
> StringJoin[Riffle[letters, " "]]
>
> hth,
>
> albert
>

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Combining elements of a list
  • Next by Date: Epic Epic HeavisideTheta problem
  • Previous by thread: Re: Combining elements of a list
  • Next by thread: Re: Running Mathematica code using DOS