Dictionary
를 초기화하는 여러가지 방법
빈 딕셔너리를 생성하는 가장 기본적인 방법
var emptyDict = [String: Int]()
키-값 쌍을 직접 지정하여 딕셔너리 생성
let exampleDict = ["a": 1, "b": 2, "c": 3]
배열의 튜플을 사용하여 딕셔너리 생성
let pairs = [("a", 1), ("b", 2), ("c", 3)]
let dictFromPairs = Dictionary(uniqueKeysWithValues: pairs)
시퀀스를 사용하여 딕셔너리를 생성할 수 있다. 각 요소가 (key, value)
튜플이어야 함
let keys = ["a", "b", "c"]
let values = [1, 2, 3]
let dictFromZip = Dictionary(uniqueKeysWithValues: zip(keys, values))
클로저 사용해 키-값 변환하여 딕셔너리를 생성
let array = ["a", "b", "c"]
let dictFromMap = Dictionary(uniqueKeysWithValues: array.enumerated().map { ($1, $0 + 1) })
let dictWithDefault = Dictionary(uniqueKeysWithValues: zip(keys, values), defaultValue: 0)