View Problem

Check if a key exists in a map

Given a map pets {joe:cat,mary:turtle,bill:canary} print "ok" if an pet exists for "mary"
DiskEdit
python
pets = dict(joe='cat', mary='turtle', bill='canary')
if ("mary" in pets) print "ok"
DiskEdit
clojure
(if (contains? '{joe cat mary turtle bill canary} 'mary)
(println "ok"))
ExpandDiskEdit
fsharp
if (Map.mem "mary" pets) then printfn "ok"
ExpandDiskEdit
fsharp
if pets.ContainsKey("mary") then printfn "ok"
ExpandDiskEdit
fantom
map := ["joe":"cat", "mary":"turtle", "bill":"canary"]
if (map.containsKey("mary")) echo("ok")
ExpandDiskEdit
java
if (pets.containsKey("mary")) System.out.println("ok");
ExpandDiskEdit
cpp C++/CLI .NET 2.0
if (pets->ContainsKey("mary")) Console::WriteLine("ok");
ExpandDiskEdit
cpp
if (pets.find("mary") != pets.end()){
std::cout << "ok" << std::endl;
}
ExpandDiskEdit
cpp
if (pets.count("mary") > 0)
cout << "ok" << endl;

Submit a new solution for python, clojure, fsharp, fantom ...
There are 19 other solutions in additional languages (erlang, go, groovy, haskell ...)