Given an empty pets map, add the mapping from
"rob" to
"dog"
python pets['rob'] = 'dog'
pets['rob'] = 'dog'
fsharp pets <- (Map.add "rob" "dog" pets)
#light
open System
open System.Collections
let mutable pets = Map.empty
pets <- (Map.add "rob" "dog" pets)
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
fsharp pets.Add("rob", "dog")
#light
open System
open System.Collections
let pets = new Generic.Dictionary<string, string>()
pets.Add("rob", "dog")
for pet in pets do printfn "%s -> %s" (pet.Key) (pet.Value) done
Submit a new solution for
python or
fsharp
There are 19 other solutions in
additional languages (
clojure,
cpp,
erlang,
fantom ...)