开发者

lists:append with list comprehensions

开发者 https://www.devze.com 2023-02-19 21:57 出处:网络
How can I define lists:append function with list comprehension? I want something li开发者_Go百科ke

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 ].
0

精彩评论

暂无评论...
验证码 换一张
取 消