[erlang-questions] list comprehension of two lists

Wes James comptekki@REDACTED
Fri Jun 18 23:55:19 CEST 2010


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


More information about the erlang-questions mailing list