Re: Re: Making a lists with conditions

• To: mathgroup at smc.vnet.net
• Subject: [mg85756] Re: [mg85698] Re: Making a lists with conditions
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Thu, 21 Feb 2008 17:58:22 -0500 (EST)
• References: <fpduuo\$rd3\$1@smc.vnet.net> <200802191203.HAA19554@smc.vnet.net>

```Here is a way that seems sufficiently different from the others that I
have seen to be pehraps worth posting:

list1 = {3.8, 3.85, 3.9, 3.95, 4., 4.05, 4.1};
list2 = {{3.85, 120}, {4.0, 111}, {4.1, 314}};

Union[list1 /. (x_)?NumberQ -> {x, \$}, list2,  SameTest -> (First[#1]
== First[#2] &)]/. \$ -> 0

{{3.8, 0}, {3.85, 120}, {3.9, 0}, {3.95, 0},
{4., 111}, {4.05, 0}, {4.1, 314}}

Andrzej Kozlowski

> On Feb 18, 11:02 pm, Guillermo Sanchez <guillermo.sanc... at hotmail.com>
> wrote:
>> Dear group
>>
>> I have two list (list1:{a1, ...ai,  aj, ..., an}, list2:{{ai,
>> bi}, ..., {aj, bj}}.
>>
>> I wish to obtain a new list (list3} where be included all members of
>> list1 and list2. If elements ak is not included in list2 then write
>> {ak, 0}.
>>
>> Here is an example:
>>
>> list1 = {3.8,  3.85, 3.9,  3.95,  4., 4.05,  4.1};
>> list2 = {{3.85, 120}, { 4.0 , 111}, {4.1, 314}};
>>
>> ff[list1_, list2_] := =BFlist1, list2?
>>
>> Here is the ouput that I wist to obtain
>>
>> Out:={{3.8, 0} , {3.85`, 120}, {3.9`, 0}, {3.95, 0}, {4.`, 111},
>> {4.05`, 0}, {4.1`, 314}}
>>
>> I have a method but it is two complicate. I am sure that some members
>> of the group will find a elegant solution
>>
>> Thanks
>>
>> Guillermo

```

• Prev by Date: RE: Extracting the value from Solve
• Next by Date: Re: Extracting the value from Solve
• Previous by thread: Re: Making a lists with conditions
• Next by thread: Re: Making a lists with conditions