MathGroup Archive 2009

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

Search the Archive

Re: Re: Transforming a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103194] Re: [mg103130] Re: [mg103108] Transforming a list
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Thu, 10 Sep 2009 07:20:48 -0400 (EDT)
  • References: <200909080958.FAA26578@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

To me, this is totally unexpected... but it's the last example under  
"Applications" on the Help page for Flatten.

Bobby

On Wed, 09 Sep 2009 03:40:55 -0500, Thomas Dowling  
<thomasgdowling at gmail.com> wrote:

> Hello,
>
> lst = {{c, e, g}, {d, f}, {e, g}, {f}, {g}, {}};
>
>
> In[116]= Flatten[lst, {{2}, {1}}]
>
>
> Out[116]= {{c, d, e, f, g}, {e, f, g}, {g}}
>
>
>> From Carl Woll originally, I think.
>
>
> Good luck
>
> Tom Dowling
>
>
>
>
>
> On Tue, Sep 8, 2009 at 10:58 AM, Don <donabc at comcast.net> wrote:
>
>> I am given: lst =  {{c, e, g}, {d, f}, {e, g}, {f}, {g}, {}}
>>
>> I want to form a list of sublists where the first sublist consists of  
>> the
>> first elements
>> from each sublist of lst, the second sublist the second elements from  
>> each
>> of the sublists of lst etc.
>>
>> The final outcome should be:
>> {{c, d, e, f, g}, {e, f, g}, {g}}
>>
>> I can do this by first padding the sublists of lst (to make them the  
>> same
>> length)and then using Transpose. But how to get rid of the trailings  
>> 0's?
>>
>> For example:
>>
>> newLst = Map[PadRight[#, Length[lst[[1]]]] &, lst]
>>
>> Transpose[newLst]
>>
>> which produces:
>>
>> {{c, d, e, f, g, 0}, {e, f, g, 0, 0, 0}, {g, 0, 0, 0, 0, 0}}
>>
>> Is there a better way to end up with
>>
>> {{c, d, e, f, g}, {e, f, g}, {g}}
>>
>> Thank you.
>>
>>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: how to get the longest ordered sub sequence of a list
  • Next by Date: Re: how to get the longest ordered sub sequence of a
  • Previous by thread: Re: Transforming a list
  • Next by thread: Re: Re: Transforming a list