A = [1,2,3]
The output should be:
[1,one,2,two,3,three]
Is it possible to get such an output?
A = [1,2,3]
The output should be:
[1,one,2,two,3,three]
Is it possible to get such an output?
Yes, you can put two clauses in the comprehension and make the second one return two elements for each element in the first one:
1> F = fun
1> (1) -> "one";
1> (2) -> "two";
1> (3) -> "three"
1> end.
#Fun<erl_eval.6.127694169>
2> [B || A <- [1, 2, 3], B <- [A, F(A)]].
[1,"one",2,"two",3,"three"]
i think the out put of last code would be
[[1 ,"one"] , [2, "two"] , [3 , "tree"]].
some right answer will be
lists:append([begin T = case I of
1 -> "One" ;
2->"Two";
3->"Three";
_ -> "" end ,
[I ,T] end
|| I <- lists:seq(1,3)]).