Logo

Programming-Idioms

You have a Point with integer coordinates x and y. Create a map m with key type Point (or equivalent) and value type string. Insert "Hello" at position (42, 5).
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "dart:math";
Map<Point, String> m = {};
m[Point(42, 5)] = "Hello";
m := map[Point]string{}
p := Point{x: 42, y: 5}
m[p] = "Hello"
import qualified Data.Map.Strict as Map
type Point = (Integer, Integer)
m :: Map.Map Point String
m = Map.empty
m' = Map.insert (42, 5) "Hello" m
import java.util.HashMap;
import java.util.Map;
Map<Point, String> m = new HashMap<>();
m.put(new Point(42, 5), "Hello");
use strict;
my %m;
my $p = Point->new(x => 42, y => 5);

$m{$p} = 'Hello';
m = dict()
p = Point(x=42, y=5)
m[p] = 'Hello'
from collections import namedtuple
Point = namedtuple('Point', 'x y')

p = Point(42, 5)

m = {p: "Hello"}
m = {Point(42, 5): 'Hello'}
Point = Struct.new(:x, :y)
m = {Point.new(42, 5) => "Hello"}
use std::collections::HashMap;
let mut map: HashMap<Point, String> = HashMap::new();
map.insert(Point { x: 42, y: 5 }, "Hello".into());