[Character: Int] = [:] source.map { frequencies[$0, default: 0] += 1 } frequencies // ["w": 1, "r": 1, "e": 1, "o": 2, "l": 3, ",": 1, " ": 1, "h": 1, "d": 1] let x = frequencies["a", default: 0] // Does not store `0` at `a`; let y = frequencies["a"] ?? 0 // these lines are equivalent let numbers = ["one": 1, "two": 2, "three": 3, "four": 4] let strings = numbers.mapValues(String.init) // ["three": "3", "four": "4", "one": "1", "two": "2"] let evens = numbers.filter { $0.value % 2 == 0 } // ["four": 4, "two": 2] 7 — Bas Broek, 18.01.2017