How do I have multiple generators for list comprehensions in F#?
I am trying to write something 开发者_开发百科like this
[(x,y)|x<- [1,2,3], y <- [’a’,’b’]]
=> [(1,’a’),(1,’b’),(2,’a’),(2,’b’),(3,’a’),(3,’b’)]
[for x in [1;2;3] do
for y in ['a';'b'] do
yield x,y]
just another fun way
[1;2;3] |> List.map ( fun X -> ['a';'b'] |> List.map (fun A -> X,A) )
F# equivalent.
List.zip [1;2;3] ['a';'b';'c']
精彩评论