Last active
September 28, 2016 06:34
-
-
Save ken0nek/b66492cc4368e3d323ba to your computer and use it in GitHub Desktop.
【Swift】2つの配列から辞書を作る ref: http://qiita.com/ken0nek/items/8e97692eeaeda6eb5770
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let romanStrs = ["M", "D", "C", "L", "X", "V", "I"] | |
let romanNums = [1000, 500, 100, 50, 10, 5, 1] | |
let romanToNum = zip(romanStrs, romanNums).reduce([String: Int]()) { (dic, t) in | |
var dic = dic | |
dic[t.1] = t.0 | |
return dic | |
} | |
print(romanToNum) | |
// ["X": 10, "V": 5, "D": 500, "C": 100, "L": 50, "I": 1, "M": 1000] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment