Module 02 Β· Collections β Lesson 2 of 3 Β· ~11 min
Maps
Looking things up by key
A slice is great for an ordered list. But often you want to look something up by a key: the rating for a given walker ID, the price for a given duration. That's a map β Go's dictionary.
The type spells out both halves: map[KeyType]ValueType.
map[string]intβ string keys, int values (walker ID β rating).map[int]intβ int keys, int values (duration in minutes β price in cents).
This is Swift's
Dictionary<Key, Value>β same idea, terser syntax. Keys are unique; assigning to an existing key overwrites it.