[erlang-questions] list comprehension of two lists

Robert Virding rvirding@REDACTED
Fri Jun 18 23:58:37 CEST 2010


Or try lists:zipwith/3 to do it one go.

Robert

On 18 June 2010 23:55, Wes James <comptekki@REDACTED> wrote:
> On Fri, Jun 18, 2010 at 3:51 PM, Håkan Stenholm
> <hokan.stenholm@REDACTED> wrote:
>> Wes James wrote:
>>>
>>> I see how to do:
>>>
>>> [X || X <- [1,2,3,4,5,6]]
>>>
>>> will create [1,2,3,4,5]
>>>
>>> but how about I have two lists, [1,2,3] and [a,b,c] and I want to output
>>>
>>> [[1,a], [2,b], [3,c]]
>>>
>>> can that be done with a list comprehension?
>>>
>>> thx,
>>>
>>> -wes
>>>
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>>>
>>>
>>>
>>
>> lists:zip([1,2,3], [a,b,c]).          ->
>>
>> [{1,a},{2,b},{3,c}]
>>
>>
>> [[A,B] || {A,B} <- lists:zip([1,2,3], [a,b,c])].         ->
>>
>>
>> [[1,a],[2,b],[3,c]]
>>
>
> Håkan, thx - that was too simple....
>
> -wes
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list