How to convert array to dictionary in F#

1 Answer

0 votes
let arr = [|1; 2; 3; 4; 5|]

let dictionary = dict [ for v in arr -> v, if v % 2 = 1 then "Odd" else "Even" ]

for dic in dictionary do
    printfn "%d - %s" dic.Key dic.Value
    
    
    
(*
run:

1 - Odd
2 - Even
3 - Odd
4 - Even
5 - Odd

*)

 



answered Mar 9, 2021 by avibootz

Related questions

1 answer 210 views
1 answer 241 views
1 answer 219 views
219 views asked Mar 8, 2021 by avibootz
1 answer 229 views
1 answer 223 views
1 answer 222 views
2 answers 276 views
...