How can I define lists:append
function with list comprehension?
I want something li开发者_Go百科ke
1> append([[1, 2, 3], [a, b], [4, 5, 6]]).
[1,2,3,a,b,4,5,6]
Remember that you can use elements from a generator in a later generator in the same list comprehension!
1> Lists = [[1, 2, 3], [a, b], [4, 5, 6]].
[[1,2,3],[a,b],[4,5,6]]
2> [N || L <- Lists, N <- L].
[1,2,3,a,b,4,5,6]
[Y || X <- [[1,2,3],[a,b],[4,5,6]], Y <- X ].
精彩评论