RosettaCodeData/Task/Associative-array-Creation/OCaml/associative-array-creation-7.ocaml
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

7 lines
234 B
Text

let dict = ["foo", 5; "bar", 10; "baz", 15]
(* retrieve value *)
let bar_num = try List.assoc "bar" dict with Not_found -> 0;;
(* see if key exists *)
print_endline (if List.mem_assoc "foo" dict then "key found" else "key missing")