Programming
Bash
Arrays
Regex - grep
Strings
C
Arrays
Regex - POSIX
Strings
C++
Arrays
Bimaps
Functions
Maps
Regex
Strings
Go
Arrays
Maps
Initialise
Insert
Overwrite
Count
Retrieve by key
Remove
Search
Iterate
Strings
Java
Arrays
Regex
Strings
JavaScript
Arrays
Functions
Objects
Regex
Strings
Perl
Arrays
Regex
Strings
Python
Arrays
Functions
Regex
Strings
Go Maps
Initialise
Fixed contents n/a var a = map[string]string{
  "one" : "un",
  "two" : "deux",
}
one=un two=deux
Insert
Insert k,v pair var a = make(map[string]string)
var k="one"
var v="un"
a[k]=v
one=un
Overwrite
Overwrite k,v pair var a = map[string]string{
  "one" : "un",
  "two" : "deux",
}
var k="one"
var v="1"
a[k]=v
one=1 two=deux
Count
Length of map var a = map[string]string{
  "one" : "un" ,
  "two" : "deux" ,
  "three" : "trois",
};
var n=len(a)
3
Retrieve by key
Retrieve value v associated with key k var a = map[int]string{
  1 : "un",
  2 : "deux",
  3 : "trois",
};
var k=2;
var v=a[k];
deux
Retrieve empty value var a = map[string]int{
  "un" : 1,
  "deux" : 2,
  "trois" : 3,
}
var k="quatre"
var v=a[k]
0
Remove
Remove item by key k var a = map[int]string{
  1 : "un",
  2 : "deux",
  3 : "trois",
}
var k=3;
delete(a, k)
1=un 2=deux
Remove items by iterator i whilst iterating over map var a = map[int]string{
  1 : "un",
  2 : "deux",
  3 : "trois",
}
for k,v := range a {
    if v == "un" || v == "deux" {
        delete(a, k)
    }
}
3=trois
Search
Test element 'k' 'is in' map var a = map[int]string{
  1 : "un",
  2 : "deux",
  3 : "trois",
}
var k=2;
var _, t = a[k]
1
Test element 'k' 'is in' map var a = map[int]string{
  1 : "un",
  2 : "deux",
  3 : "trois",
}
var k=4;
var _, t = a[k]
0
Iterate
Iterate over map 'a' keys var a = map[int]string{
  1 : "apple",
  2 : "banana",
  3 : "cherry",
}
var b[]int
for k := range a {
  b=append(b,k)
}
sort.Ints(b)
1 2 3
Iterate over map 'a' values var a = map[int]string{
  1 : "apple",
  2 : "banana",
  3 : "cherry",
}
var b[]string
for _, v := range a {
  b=append(b,v)
}
sort.Strings(b)
apple banana cherry