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


Groups > comp.soft-sys.math.maple > #891 > unrolled thread

Merging two lists

Started byrouben@shadow.(none) (Rouben Rostamian)
First post2014-06-15 03:38 +0000
Last post2014-06-15 11:02 -0700
Articles 6 — 4 participants

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


Contents

  Merging two lists rouben@shadow.(none) (Rouben Rostamian) - 2014-06-15 03:38 +0000
    Re: Merging two lists Axel Vogt <&noreply@axelvogt.de> - 2014-06-15 19:56 +0200
      Re: Merging two lists Rainer Rosenthal <r.rosenthal@web.de> - 2014-06-16 00:27 +0200
        Re: Merging two lists rouben@shadow.(none) (Rouben Rostamian) - 2014-06-16 20:17 +0000
    Re: Merging two lists Joe Riel <joer@san.rr.com> - 2014-06-15 10:58 -0700
      Re: Merging two lists Joe Riel <joer@san.rr.com> - 2014-06-15 11:02 -0700

#891 — Merging two lists

Fromrouben@shadow.(none) (Rouben Rostamian)
Date2014-06-15 03:38 +0000
SubjectMerging two lists
Message-ID<lnj4fm$mon$1@news.albasani.net>
Let's say I have the following two lists:
M := [a,b,c,d];
N := [e,f,g,h];

I want to create a list of pairs, as in:
[[a, e], [b, f], [c, g], [d, h]]

Here is how I do it:
[seq([M[i],N[i]], i=1..nops(M))];

but that's too pedestrian.  Is there a neater and more elegant
way of doing this?

-- 
Rouben Rostamian

[toc] | [next] | [standalone]


#892

FromAxel Vogt <&noreply@axelvogt.de>
Date2014-06-15 19:56 +0200
Message-ID<c0653qFaeruU1@mid.individual.net>
In reply to#891
On 15.06.2014 05:38, none Rouben Rostamian wrote:
> Let's say I have the following two lists:
> M := [a,b,c,d];
> N := [e,f,g,h];
>
> I want to create a list of pairs, as in:
> [[a, e], [b, f], [c, g], [d, h]]
>
> Here is how I do it:
> [seq([M[i],N[i]], i=1..nops(M))];
>
> but that's too pedestrian.  Is there a neater and more elegant
> way of doing this?
>

 From the help for 'zip':

   zip(`[]`,M ,N);
                    [[a, e], [b, f], [c, g], [d, h]]

where I find pedestrian's way much more clear.

[toc] | [prev] | [next] | [standalone]


#895

FromRainer Rosenthal <r.rosenthal@web.de>
Date2014-06-16 00:27 +0200
Message-ID<c06ku4Fdn4jU1@mid.individual.net>
In reply to#892
Am 15.06.2014 19:56, schrieb Axel Vogt:
> On 15.06.2014 05:38, none Rouben Rostamian wrote:
>> Let's say I have the following two lists:
>> M := [a,b,c,d];
>> N := [e,f,g,h];
>>
>> I want to create a list of pairs, as in:
>> [[a, e], [b, f], [c, g], [d, h]]
>>
>> Here is how I do it:
>> [seq([M[i],N[i]], i=1..nops(M))];
>>
>> but that's too pedestrian.  Is there a neater and more elegant
>> way of doing this?
>>
> 
>  From the help for 'zip':
> 
>    zip(`[]`,M ,N);
>                     [[a, e], [b, f], [c, g], [d, h]]
> 
> where I find pedestrian's way much more clear.
> 

Maple V doesn't have it that short, but zip works as follows:
zip((x,y)->[x,y],M ,N);

I did not know "zip" until now. Thanks for telling.

Cheers,
Rainer

[toc] | [prev] | [next] | [standalone]


#896

Fromrouben@shadow.(none) (Rouben Rostamian)
Date2014-06-16 20:17 +0000
Message-ID<lnnjd4$5dl$1@news.albasani.net>
In reply to#895
In article <c06ku4Fdn4jU1@mid.individual.net>,
Rainer Rosenthal  <r.rosenthal@web.de> wrote:
>Am 15.06.2014 19:56, schrieb Axel Vogt:
>> On 15.06.2014 05:38, none Rouben Rostamian wrote:
>>> Let's say I have the following two lists:
>>> M := [a,b,c,d];
>>> N := [e,f,g,h];
>>>
>>> I want to create a list of pairs, as in:
>>> [[a, e], [b, f], [c, g], [d, h]]
>>>
>>> Here is how I do it:
>>> [seq([M[i],N[i]], i=1..nops(M))];
>>>
>>> but that's too pedestrian.  Is there a neater and more elegant
>>> way of doing this?
>>>
>> 
>>  From the help for 'zip':
>> 
>>    zip(`[]`,M ,N);
>>                     [[a, e], [b, f], [c, g], [d, h]]
>> 
>> where I find pedestrian's way much more clear.
>> 
>
>Maple V doesn't have it that short, but zip works as follows:
>zip((x,y)->[x,y],M ,N);
>
>I did not know "zip" until now. Thanks for telling.

Thank you all for the many insightful and varied answers to
my question in this thread.  I knew about the zip function
at one point but had forgotten it.  Of the various solutions,
the one noted above by Rainer appeals to me most; I find
it more expressive.

Rouben

[toc] | [prev] | [next] | [standalone]


#893

FromJoe Riel <joer@san.rr.com>
Date2014-06-15 10:58 -0700
Message-ID<87mwdedphl.fsf@san.rr.com>
In reply to#891
rouben@shadow.(none) (Rouben Rostamian) writes:

> Let's say I have the following two lists:
> M := [a,b,c,d];
> N := [e,f,g,h];
>
> I want to create a list of pairs, as in:
> [[a, e], [b, f], [c, g], [d, h]]
>
> Here is how I do it:
> [seq([M[i],N[i]], i=1..nops(M))];
>
> but that's too pedestrian.  Is there a neater and more elegant
> way of doing this?

(**) zip(`[]`,M,N);
                  [[a, e], [b, f], [c, g], [d, h]]

(**) `[]`~(M,N);   
                  [[a, e], [b, f], [c, g], [d, h]]


-- 
Joe Riel

[toc] | [prev] | [next] | [standalone]


#894

FromJoe Riel <joer@san.rr.com>
Date2014-06-15 11:02 -0700
Message-ID<87ioo2dpb5.fsf@san.rr.com>
In reply to#893
Joe Riel <joer@san.rr.com> writes:

> rouben@shadow.(none) (Rouben Rostamian) writes:
>
>> Let's say I have the following two lists:
>> M := [a,b,c,d];
>> N := [e,f,g,h];
>>
>> I want to create a list of pairs, as in:
>> [[a, e], [b, f], [c, g], [d, h]]
>>
>> Here is how I do it:
>> [seq([M[i],N[i]], i=1..nops(M))];
>>
>> but that's too pedestrian.  Is there a neater and more elegant
>> way of doing this?
>
> (**) zip(`[]`,M,N);
>                   [[a, e], [b, f], [c, g], [d, h]]
>
> (**) `[]`~(M,N);   
>                   [[a, e], [b, f], [c, g], [d, h]]

also

(**) ListTools:-Transpose([M,N]);
                   [[a, e], [b, f], [c, g], [d, h]]

-- 
Joe Riel

[toc] | [prev] | [standalone]


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


csiph-web